I’ve got a script setup to turn particle effects on for an ability, play for specified ability time and then go on cool down. Now one of my abilities is triggering a particle effect on my player as well as on another object.
I have it setup so that when the player is in the object’s collider the specified key will turn the particles on. This all works fine except when I used the ability outside of the collider. In this case, the player’s particles will turn on which is what I want, but then if I move into the collider and use the ability again it will trigger only that objects particles.
Problem is essentially that both sets of particles need to be on cooldown at the same time, regardless of if my player is in the collider to trigger the objects set of particles.
I’d actually like to find a way that I could just put my “fire2” input itself on cooldown for X Seconds globally but haven’t figured that out either.
This is the script on my non player object:
#pragma strict
var MobisPlaying = false;
var MobcoolDown = 1.5;
function OnTriggerStay (other : Collider) {
if (!MobisPlaying && Input.GetButtonUp("Fire2")) {
PlayMPS();
}
}
function PlayMPS() {
MobisPlaying = true;
particleSystem.Play();
yield WaitForSeconds(0.5);
particleSystem.Stop();
yield WaitForSeconds(MobcoolDown);
MobisPlaying = false;
}
This is what is on my player:
#pragma strict
var isPlaying = false;
var coolDown = 1.5;
function Update() {
if (!isPlaying && Input.GetButtonUp("Fire2")) {
PlayPS();
}
}
function PlayPS() {
isPlaying = true;
particleSystem.Play();
yield WaitForSeconds(0.5);
particleSystem.Stop();
yield WaitForSeconds(coolDown);
isPlaying = false;
}