how do I get a function from another script and insert it into a button, I did this is giving this error
"Object reference not set to an instance of an object"
public Button Mybutton;
void Indice(){
if (index <= 0)
{
index = 0;
}
if (index >= 2)
{
index = 2;
}
if (index == 0)
{
Mybutton.GetComponent<Button>().GetComponent<MyScript>().MyFunction();
}
else if (index == 1)
{
Mybutton.GetComponent<Button>().GetComponent<MyScript>().MyFunction2();
}
else if (index == 2)
{
Mybutton.GetComponent<Button>().GetComponent<MyScript>().MyFunction3();
}
MyButtonis already of typeButton, soMybutton.GetComponent<Button>()is redundant. But if ultimately what you want is aMyScript, why not just make your variablepublic MyScript myScriptInstance;instead? \$\endgroup\$