- Home /
void OnMouseDown not working
can someone tell me why this void onMouseDown isn't working? I wrote it correctly. void OnMouseDown() { hook = wall.AddComponent(typeof(SpringJoint)) as SpringJoint; hook.connectedBody = UwU; Debug.Log("hook"); }
Answer by deniskotpletnev · Jul 25, 2020 at 11:31 PM
Try to write like this:
private void Update
{
if (Input.GetMouseButton(0))
{
hook = wall.AddComponent(
typeof(SpringJoint)) as SpringJoint;
hook.connectedBody = UwU;
Debug.Log("hook");
}
}
Answer by logicandchaos · Jul 26, 2020 at 02:42 AM
Google is your friend:
https://stackoverflow.com/questions/28916663/unity-c-sharp-onmousedown-does-not-work-why
https://answers.unity.com/questions/486847/onmousedown-doesnt-work-1.html
https://answers.unity.com/questions/1173594/onmousedown-not-firing-even-though-attached-to-col.html
https://answers.unity.com/questions/425478/onmousedown-not-firing.html
Or you could try Unity.EventSystems, works great whenever I used it.
Answer by DripSta · Jul 26, 2020 at 05:29 AM
Have you made sure that the object you want the onMouseDown to work on, has a collider attached to it. Cause the onMouseMove function won't work unless a collider is attached to the gameobject