0

I have been trying to find an aswer to this for hours. I am trying to get the button GameObject that accessed a function on one of my scripts. I just need to know which button accessed the script. Please help in UNITYSCRIPT!

1 Answers1

0

You can make a public string variable in the main script which will be hold the name of the button which accesed the script

public string clickedButtonName;

In buttons you are gonna add another script which will updates clickedButtonName variable with GetComponent

Pseudo code

Button Script that will be called on Click;

public Gameobject yourMainScriptObject;

public void buttonClicked()
{
     yourMainScriptObject.GetComponent<YourMainScript>().clickedButtonName = gameObject.name.toString();
}

So when a button is clicked they will update the string value on the main script with their name.

Hope this helps! Cheers!

Thalthanas
  • 496
  • 6
  • 10