Trouble with Mousedown/up check

Hey guys,

I’m sorta having trouble with a script im creating, its function is allow the player to pickup objects, and when the object is dropped it adds a force to it, how ever my problem is regarding the GetMouseButtonDown.

which only checks when the mouse down is pressed the first and only first time, same with up.

they are in a update function, so it doesnt realyl makes to me, i want to be able to check while mouse button is down, do this and keep doing it, when mouse button is let go, add some force to the object.

but it doesnt seem to be working, sorry if i didnt explain this well, its my first answers post, i am also fairly new to unity,

Thanks for reading and helping

public bool a;

void Update()

{

if(Input.GetMouseButtonDown)

a=true;

}

Use GetMouseButton instead.

Hope this can help:

using UnityEngine;

public class Example: MonoBehaviour 
{

bool isMouseDown = false;

     void OnMouseUp()
        {
              isMouseDown = false;
        }
        
        void OnMouseDown()
        {
               isMouseDown = true;
        }

       void Update()
       {
             if(isMouseDown)
            {
                 // Do Stuff
            }
       }
}

Use either Input.GetMouseButton or Input.GetButton(“Fire”)…
Then put them in your Update function.