So this sits on my powerup and I want to transform it depending on what button is clicked. How can I pass info what button was clicked so the case is switched?
public enum PowerUps
{
ARROW,
REVERSE,
THIRD
}
public PowerUps ActivePowerUp = PowerUps.ARROW;
void Start()
{
GameManager.onClick += TransformPowerUp;
}
public void TransformPowerUp()
{
switch (ActivePowerUp)
{
case PowerUps.ARROW:
Debug.Log("ARROW");
break;
case PowerUps.REVERSE:
Debug.Log("REVERSE");
break;
case PowerUps.THIRD:
Debug.Log("THIRD");
break;
default:
Debug.Log("NOTHING");
break;
}
For the buttons I have the following in my gamemanager script
public delegate void ActionClick();
public static event ActionClick onClick;
public void ButtonClick()
{
//Checks if there are any listeners
if (onClick != null)
onClick();
}
In your GameManager script, where you are defining the onClick event, you should be able to make that event use a parameter, to pass the correct powerup to the script. Something like this…
public delegate void onCliick(PowerUps SelectedPowerUp);
public static event onClickHandler onClick;
public static void onClick(PowerUps SelectedPowerUp)
{
if (onClick != null)
onClick(SelectedPowerUp);
}
I just wrote this directly in the code window, so no guarantees against typos
Then in your button event, just pass the correct PowerUp to the OnClick event.
You would also need to change the declaration of TransformPowerUp to accept the parameter, like this…
public void TransformPowerUp(PowerUp ActivePowerUp)
Hope this helps,
-Larry
Hi @Larry-Dietz
There are three buttons and they all use the ButtonClick function. It doesn’t seem to work. I want the gameObject to transform based on the case, using enums. I tried adapting what you gave me, but it’s not working.
public delegate void onClick(PowerUps ActivePowerUp);
public static event ActionClick onClick;
public void ButtonClick(PowerUps ActivePowerUp)
{
//Checks if there are any listeners
if (onClick != null)
onClick();
}
AND:
public enum PowerUps
{
ARROW,
REVERSE,
THIRD
}
public PowerUps ActivePowerUp = PowerUps.ARROW;
void Start()
{
GameManager.onClick += TransformPowerUp;
}
public void TransformPowerUp(PowerUps ActivePowerUp)
{
switch (ActivePowerUp)
{
case PowerUps.ARROW:
Debug.Log("ARROW");
break;
case PowerUps.REVERSE:
Debug.Log("REVERSE");
break;
case PowerUps.THIRD:
Debug.Log("THIRD");
break;
default:
Debug.Log("NOTHING");
break;
}