Do not know how to use coroutines in Unity3D

前端 未结 3 671
被撕碎了的回忆
被撕碎了的回忆 2021-02-14 16:28

In Unity3D, this is my code:

void ActivateBuff1(){
    gun.equippedGun.msPerShot /= 2;
    gun.equippedGun.shotsLeftInMag += 10;
    StartCoroutine (WaitRage ())         


        
3条回答
  •  野的像风
    2021-02-14 16:54

    Man, Serlite said everything.. However I would have dealt with this kind of situation differently.

    If I got it right, you setted this ActivateBuff function in the script attached to some kind of item that sets a modifier in the equipped gun and afterwards gets disabled. Instead of doing that, I would just create a Buff function in the equipped gun script(passing the modifier and the time as params) and let the gun itself to handle this.

    Since the equipped gun won't disappear, it would solve your problem and ideally could even be a more generic solution. Once you could pass through another power up which could lately generate some unexpected behavior(because there would be many scripts buffing and unbuffing the gun).

提交回复
热议问题