I’m creating a runner game where the player gets a speed boost after running into a ‘boost coin’
this is what i have so far, but it’s not working. can anyone help me?
public class Booster : Coin
{
public float bonusTime;
public float bonusGain = 500f;
private bool picked = false;
private float timer = 20f;
void OnTriggerEnter(Collider other)
{
if (other.gameObject.tag == "Player")
{
picked = true;
GameObject.FindGameObjectWithTag("Player").GetComponent<ControlRunner>().speedRunner += bonusGain;
Destroy(gameObject);
}
}
void Update()
{
if (picked == true)
{
timer += Time.deltaTime;
if (timer >= bonusTime)
{
GameObject.FindGameObjectWithTag("Player").GetComponent<ControlRunner>().speedRunner -= bonusGain;
Destroy(gameObject);
}
}
}
}