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?
The gameobject with this script gets destroyed when the power-up is triggered, so it can only happen once. I also noticed that the "pickup" variable is never used. Maybe you want to destroy that one instead of the gameobject in OnTriggerEnter ?
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);
}
}
}
And all of a sudden everything works. I used your advice and it now does everything it's supposed to. Thanks! I don't understand why I was able to only change the timer once though. This game object is continuously instantiated on enemy kills. Why is destroying it when colliders touch disrupting the whole functionality though?
The gameobject with this script gets destroyed when the power-up is triggered, so it can only happen once. I also noticed that the "pickup" variable is never used. Maybe you want to destroy that one instead of the gameobject in OnTriggerEnter ?
– doublemax