Code

Hi all,

I have two buttons controlling two bools and another gameobject reading these bools and if they are true I want stuff to happen. If I press the “next button” everything works! AKA Debug.Log(“Next is true”) shows up in console.

But if I press the “last button” the Debug.Log(“Last is true”) dont show up even though I can see in the inspector that the button was pressed and the bool named last keeps being true.

Code on buttons

    void OnMouseDown()
    {
        //If player press the "next button" where nextGameObject has bool = true in inspector, then the public bool next should become true
        if (nextGameObject == true)
        {
            next = true;
        }
        //If player press the "last button" where lastGameObject has bool = true in inspector, then the public bool last should become true
        if (lastGameObject == true)
        {
            last = true;
        }
    }

I then set lastGameObject true on last button in inspector, and nextGameObject true for next button in inspector.

Code on another gameobject where I eventually want stuff to happen to its children when I know the code is working:

    private switchCamList switchCamList;

    // Start is called before the first frame update
    void Start()
    {
        switchCamList = FindObjectOfType<switchCamList>();
    }

    private void Update()
    {
        //If bool last from switchCamList is true then do this THIS DOES NOT EXECUTE
        if (switchCamList.last == true)
        {
            Debug.Log("Last is true");
            switchCamList.last = false;
        }
        //If bool next from switchCamList is true then do this THIS WORKS
        if (switchCamList.next == true)
        {
            Debug.Log("Next is true");
            switchCamList.next = false;
        }
    }
}

What am I missing here? Why is only the code for the next button working when the code has the same logic on the last button and the last bool is true?

Oh never mind, I of course had to reference each buttons script since I had it on two objects with different settings

if (lastBut.GetComponent().last == true)