How do I make an Ai shoot every 3 seconds?

I’m working on a game with a friend and I’m having trouble making the Ai shoot every 3 seconds.

there must be ONE THOUSAND identical questions to this. it's too much, from now on they'll just be closed #TIMERS IN UNITY .. USE "INVOKE()"

ah but not everywhere says about invoke this is the 2. time I've heard about it and will start slowly looking in to invoke thumbs up for closing and pointing the Q

Fattie is the Ambassador for Invoke and InvokeRepeating, I'm really surprised you havn't seen that before now =]

it's important to use "time" etc etc etc later in advanced programming But for timers in Unity you simply use Invoke or InvokeRepeating its just that simple. It is inconceivable that you would have to f--- around with time, comparisons, loops etc in a game engine .. to make a trivial timer The whole issue drives me freaking nuts.

no [@alu][1] when I solve my problem I don't search for the same problem any longer I even made my own structure for that as I was too aggro writing same script workaround over and over even eric at my Q didn't point me in to invoke when I started programming [1]: http://answers.unity3d.com/users/20706/alucardj.html

1 Answer

1

Basic Timer implementation

float timer;
int waitingTime;

void Update(){
    timer += Time.deltaTime;
    if(timer > waitingTime){
        //Action
       timer = 0;
    }
}

Simple and easy xD Just to improve, in this case: int waitingTime = 3