I use UI Text and add component “BoxCollaider2D”(“BoxCollaider”), but the button is not clickable. Why? Is Trigger set to true.
void OnMouseDown() {
SceneManager.LoadScene("scene2");
}
I use UI Text and add component “BoxCollaider2D”(“BoxCollaider”), but the button is not clickable. Why? Is Trigger set to true.
void OnMouseDown() {
SceneManager.LoadScene("scene2");
}
I don’t see any problem with the OnMouseDown Method part, maybe it’s something else?
Oops. I’ll take that back.
You are using new UI, don’t add colliders to buttons, just create script that implements one of the click event methods:
using UnityEngine;
using UnityEngine.EventSystems;
public class ClickToLoad: MonoBehaviour, IPointerClickHandler
{
public void OnPointerClick(PointerEventData eventData)
{
SceneManager.LoadScene("scene2");
}
}
EDIT:
but if you want to click a gameobject instead of button / other UI canvas object:
OnMouseDown works like this:
https://unity3d.com/learn/tutorials/modules/beginner/scripting/on-mouse-down
It’s meant for old GUI and Colliders.
Thanks:)