I’m a sound designer so I’m currently logging debugs for where my event triggers will go. short description of what i’m trying to do:

I have two spells with cool downs and want a different sound for each one when they finish the cool down but the spells use the same “user action” script (pictured) with public variables changed in the inspector like the countdown time or prefab effect.

How can achieve this? i’ve included some of the script which relates to the ending off the cool down and a commented out part where I attempted to solve it but it kind of describes what I want it to do.

	void Update()
	{
		if (myState == MyState.Cooldown)
		{
			if (cooldownCounter > 0f)
			{
				cooldownCounter -= Time.deltaTime;
				UpdateCooldownText();
			}
			else if (cooldownCounter <= 0f)
			{
				StopCooldown();

				Debug.Log("cooldown over but this shows for both spells ");

				//If the public gameobject "useractionprefab" in the inspector is "starburst" when the countdown finishes then play that sound

				/*if (userActionPrefab = ("StarBurst")
				{
					Debug.Log("cooldown over for starburst spell");

				} */
			}
		}
	}

96265-screen-shot-2017-06-20-at-113219.png

void Update()
{
if (myState == MyState.Cooldown)
{
if (cooldownCounter > 0f)
{
cooldownCounter -= Time.deltaTime;
UpdateCooldownText();
}
else if (cooldownCounter <= 0f)
{
StopCooldown();

                 Debug.Log("cooldown over but this shows for both spells ");
 
                 //If the public gameobject "useractionprefab" in the inspector is "starburst" when the countdown finishes then play that sound
 //             // ask if the userActionPrefab script if is starburst or not
                 if (userActionPrefab.GetComponent(UserActionPrefab).isStarburst)
                 {
                     Debug.Log("cooldown over for starburst spell");
 
                 } 
                 else{ //is the other spell
                   Debug.Log("cooldown over for starburst spell");
 
                  }
              }
         }
     }

That would work if you added a public bool called “isStarburst”.

Edit for any more then two:

oops, in the brackets you would need the userActionPrefab’s script, and if you had more then two spells then i would have an enum and use a switch statement like this small code:

[System.Serializable]
public enum Spells {Starburst,Spell2,Spell3}
//public enum Spells {starburst,spell2, spell3} //so on

//the script that is sending the spell not "Test"
public class Test : MonoBehaviour {
	
	public Spells spells;

then you would get it with a switch statement that is like this:

switch (spells) {
		case Spells.Starburst:
			{
				//is a starburst

				//then after you are finished with you code you have to have this line
				break;
			}
		case Spells.Spell2:
			{
				//is another spell

				break;
			}
		case Spells.Spell3:
			{
				//so on

				break;
			}

that code only works from the “Test script” you would have to edit it for the other scripts but that’s the idea

I figured it out by myself. If there is an easier way of doing this please let me know.

void Update()
      {
          if (myState == MyState.Cooldown)
          {
              if (cooldownCounter > 0f)
              {
                  cooldownCounter -= Time.deltaTime;
                  UpdateCooldownText();
              }
              else if (cooldownCounter <= 0f)
              {
                  StopCooldown();
  
                  Debug.Log("cooldown over but this shows for both spells ");

                  if (userActionPrefab.name.Equals("FireStorm"))

                    	{ 

                    	Debug.Log("timer reup for fire storm");
                    	}