- Home /
Toggle problem
I have a script attached to a UI object that has the following function.
public void OnClick()
{
Debug.Log("Pressed toggle");
}
I also have a toggle UI Element which is a child of this object. The toggle is set so that "On Value Changed", it calls the "OnClick" function of the script above, set to "Editor and Runtime".
It works fine in editor (meaning it outputs the "pressed toggle" line), but when I press Play it stops working and doesn't do anything. I tried setting it to "runtime only" but it doesn't make a difference.
Any idea ?
Answer by Linkthehylian04 · Jun 22, 2017 at 02:15 PM
Try this instead:
if (Input.GetKey (KeyCode.Mouse0))
{
Debug.Log("Pressed Toggle");
}
If you are trying to use a left click, this should work. If you are using right click, try Keycode.Mouse1
instead of Keycode.Mouse0
.
Nah, the OnClick is just a name. I don't want it to react at any mouse click, I want the toggle UI element to call the function -poorly- called OnClick().
It works in edit mode, not at runtime, repeatedly clicking the "Is On" checkbox in the inspector.
Your answer
