4
Hello. I’m developing a game in which the player throws some balls (shots), so I created a powerup that decreases the time between the thrown balls. I need to make the time between the balls back to normal after a certain time.
void Update()
{
cax = GameObject.FindGameObjectWithTag ("PowerUp");
if(Input.GetButton("Fire1") && Time.time >= nextFire)
{
Fire();
nextFire = Time.time + timeBetweenBullets;
}
}
// Capturar o
//POWERUP
void OnTriggerEnter(Collider other)
{
if(other.gameObject == cax)
{
timeBetweenBullets = 0.10f;
Destroy(cax);
}
}
void Fire()
{
//BULLET
//1
// Create the Bullet from the Bullet Prefab
var bullet1 = (GameObject)Instantiate(
bulletPrefab,
bulletSpawn.position,
bulletSpawn.rotation);
// Add velocity to the bullet
bullet1.GetComponent<Rigidbody>().velocity = bullet1.transform.forward * 50;
GetComponent<AudioSource>().clip = Tiro;
GetComponent<AudioSource>().Play ();
// Destroy the bullet after 2 seconds
Destroy(bullet1, 2.0f);
//BULLET
//2
// Create the Bullet from the Bullet Prefab
var bullet2 = (GameObject)Instantiate(
bulletPrefabs,
bulletSpawns.position,
bulletSpawns.rotation);
// Add velocity to the bullet
bullet2.GetComponent<Rigidbody>().velocity = bullet2.transform.forward * 50;
GetComponent<AudioSource>().clip = Tiro;
GetComponent<AudioSource>().Play ();
// Destroy the bullet after 2 seconds
Destroy(bullet2, 2.0f);
}