Timer.deltaTime resetting once and only once instead of whenever I want.

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?

using UnityEngine;
using System.Collections;

public class PickUp : MonoBehaviour {

	float timer;
	public float powerUpDuration = 10f;

	GameObject pickup;
	ShooteyBall ShooteyBall;
	GameObject player;
	SphereCollider playerCollider;

	void Awake () {
		timer = 0f;
		player = GameObject.FindGameObjectWithTag ("Player");
		ShooteyBall = player.GetComponent<ShooteyBall> ();
		playerCollider = player.GetComponent<SphereCollider> ();
		ShooteyBall = player.GetComponent<ShooteyBall> ();
	}

	void ShootyTime(){
		timer = 0f;
		ShooteyBall.timeBetweenBullets = 0.05f;
	}

	void NoMoreShooty(){
		ShooteyBall.timeBetweenBullets = 0.15f;
	}


	void Update () {
		timer += Time.deltaTime;
		if (timer >= powerUpDuration) {
			NoMoreShooty ();
		}
	}

	void OnTriggerEnter (Collider other){
		if (other == playerCollider){ 
			ShootyTime ();
			Destroy(gameObject, 0f);

			}
	}

}

You are destroying the object in OnTriggerEnter, also you might find it easier if you do something like:

  1. Put the powerup timer in the ShooteyBall component
  2. 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);     
             }
     }     
 }

Then in ShooteyBall something like:

    public bool powerUpApplied = false;
    public float powerUpDuration = 10f;
    public float powerUpTimer = 0f;   
    
     public void ApplyShootFasterPowerup (float duration) {
         powerUpApplied = true;
         powerUpTimer = 0f;
         powerUpDuration = duration;
         timeBetweenBullets = 0.05f;      
     }

    void cancelShootFasterPowerup(){
        timeBetweenBullets = 0.15f;
        powerUpApplied = false;
    }
 
     void Update () {
         if(powerUpApplied){
                 powerUpTimer += Time.deltaTime;
                 if (powerUpTimer >= powerUpDuration) {
                     cancelShootFasterPowerup();
                 }
         }          
     }

Oh sorry. Thanks for the answer! I hadn’t noticed the mail saying you answered me.