Static Bool - Detect if a button was clicked - Please help :)

Hello all,

I have a button in my scene that I will need to check if it was clicked. If the button as clicked and if the videoPlayer frame is at 350 I want to change the scene. I have the videoframe part figured out, I just need to check if the button was clicked.

Here is my handle button that is attached to a standard On Click UI Button.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class HandleButton : MonoBehaviour
{
    public static bool clicked = false;

    void LateUpdate()
    {
        clicked = false;
    }

    public void Click()
    {
        clicked = true;
       // Debug.Log("CLICKED");
    }
}

And here is the script that will check the video player frame and if the button was pressed.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Video;

public class operationsTentButtonScript : MonoBehaviour
{
    HandleButton handleButton;

    VideoPlayer vp;

    void Start()
    {
        vp = GetComponentInParent<VideoPlayer>();
        vp.Play();

        handleButton = GetComponent<HandleButton>();      
    }

    void Update()
    {
        if (vp.frame == 350 && HandleButton.clicked == true)
        {
            //Debug.Log("TEST");
            UnityEngine.SceneManagement.SceneManager.LoadScene("operationsTentSeq");
        }
    }
}

The line in question is this " if (vp.frame == 350 && HandleButton.clicked == true) "

What am I doing wrong please. It is driving me crazy lol

Thank you all.

Unless you click this PRECISELY on frame 350, it won’t work: the click will be set and then cleared in LateUpdate

Why not check if vp.frame >= 350 ?

Also, don’t clear it in Update, because what happens if this Update has already run when the true gets set?

Instead, clear the boolean back to false after you test and act on it too.

Here is some timing diagram help:

Try remove lateupdate click = false and put it in the if statement instead

Thanks for your reply. I want to change scene precisely at frame 350 which first part of the code works just fine.
If I have just the following it automatically triggers the SceneManager.LoadScene at frame 350. I just need to add the second condition (was the button pressed) in the if statement. Basically eventually this should do the following; if they have pressed it it will load a difference then if they have not at frame 350.

        if (vp.frame == 350)
        {
            //Debug.Log("TEST");
            UnityEngine.SceneManagement.SceneManager.LoadScene("operationsTentSeq");
        }

Thanks. I will try later today and see what I will get.