How can the bullet buff the other for a few second?

i know that a function can set the time for destroy the gameobject after a few second–(Destroy( Prefab ,2.0f):wink:
Is there a way to control the other script variable for a few second??

My method is add component (get and set the variable , set timer ) while the time is up return the variable to the gameobject and removecomponent…

Good day.

Yes, you have 2 options.

The first is use Invoke , wich allows you to runa method in the same script after X seconds. (this can solve your problem, but is not the best solution for future problems like this)

You need to learn aboout Corutines. Its SUPER EASY!

You only need to create a new fuction, but dont do it “void” type; do it "IEnumerator ", like this:

IEnumerator MyFunction()
{
Do something A
Do something B
yield return new WaitForSeconds(3);
Do something C
}

When this funciton is called, it will do A, B, will wait 3 seconds, and then will do C.

Of course, if you do this:

IEnumerator MyFunction()
{
yield return new WaitForSeconds(3);
Do A
Do B
Do C
}

It will wait 3 seconds, and then do A, then B, then C.

This was a Corutine, not a “regular function”, so to call it, you need to:

StartCoroutine( MyFunction() );

So for your problem, you can do something like this (if I understood what you need) :

StartCorutine( MyFunction(4.5f) );

IEnumerator MyFunction(float EffectTime)
{
Apply effects to Object;
yield return new WaitForSeconds(EffectTime);
Remove effects from Object;    
}

So the object will have that effects during 4.5 seconds

You can use multiple yield comands inside the method (at least needs 1), to control timing of execution. You can call again the Corutine at the end of the corutine to loop its effect, you cna do sooo many things…

Thats all! Simple, Easy and effective for your problem!

Once you are ready, go leran more about corutines, because allow you to easy repeat some function, or divide parts of a funtion in different frames, etc…

Good luck!

Bye!