1
\$\begingroup\$

My code to detect left mouse click is not working Input.GetMouseButtonDown(0) and Input.GetMouseButtonUp(0). But same code for Input.GetMouseButton(0) is working.

Code:

void FixedUpdate()
{
  #if UNITY_ANDROID
    mouseWorldPos = Camera.main.ScreenToWorldPoint(Input.mousePosition + new Vector3(0, 0, 4f));
    mouseCameraOffset = bowlingBall.position - mouseWorldPos;

    if (Input.GetMouseButtonDown(0))
    {
        Debug.Log("last");
        lastMousePos = Input.mousePosition;
    }
\$\endgroup\$
2
  • \$\begingroup\$ @S.TarıkÇetin the question that you've suggested is about continuous mouse button press but I want only once the button is pressed or not and this function Input.GetMouseButtonDown(0) is appropriate but it's not working . \$\endgroup\$ Commented May 19, 2018 at 14:36
  • \$\begingroup\$ You are right. That question is irrelevant. \$\endgroup\$ Commented May 19, 2018 at 14:54

1 Answer 1

2
\$\begingroup\$

Mouse events might be fired and lost between two consecutive FixedUpdates.

Use Update to make sure you capture all of them.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .