As the title says, my timer float insists in only resetting once per game. What I’m trying to do here is create some logic for whenever the player gets a pickup. The pickup makes the player shoot faster. I’m fairly new to scripting and have looked everywhere for the answer to this. I can’t figure it out. Help?
You are destroying the object in OnTriggerEnter, also you might find it easier if you do something like:
Put the powerup timer in the ShooteyBall component
In OnTriggerEnter tell the ShooteyBall component that a powerup has been collected, then destroy your power up
So there are two ways to do this, you can either use GetComponent or do a SendMessage to call a public method in that class eg (ApplyShootFasterPowerup). Unity - Scripting API: GameObject.SendMessage
So in Pickup something like:
public class PickUp : MonoBehaviour {
public float powerUpDuration = 10f;
void OnTriggerEnter (Collider other){
if (other == playerCollider){
other.gameObject.SendMessage("ApplyShootFasterPowerup", powerUpDuration);
Destroy(gameObject, 0f);
}
}
}