how to call function

by Rangel   Last Updated May 15, 2019 08:13 AM - source

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();
    }
Tags : unity c#


Related Questions


How to animate objects in Unity 3D

Updated July 12, 2015 13:05 PM