OnMouseDown and Input.GetMouseButtonDown

I’m using OnMouseDownin one script to select the object that the event clicks on, and I’m using Input.GetMouseButtonDown(0) to deselect the object.

The problem is that they are both firing at the same time resulting in no selection.

Is there a way to get OnMouseDown to only fire once per click?

You have to create a bool which checks if it is picked up:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class YourScript : MonoBehaviour
{

    public bool isPickedUp = false;

    private void Update()
    {
        if (Input.GetMouseButtonDown(0) && !isPickedUp) //Checks if it is picked up. ! means false.
        {
            // Your code
            isPickedUp = true;
        }

        else if (Input.GetMouseButtonDown(0) && isPickedUp) 
        {
            //Your code
            isPickedUp = false;
        }
    }
}