HUD to Gameobject instance

Im trying to copy some game does about how they make a HUD and then when u press some icon itll be a game object where you can drag N drop it. For example the game C0C where when u click the house itll eventrually be a game object and you can place it anywhere else…

I have this code

if(!IsBeingDrag){
		IsBeingDrag = true;
		GameObject instance = Instantiate(bombInstance);
		Vector3 mousePosition = new Vector3(Input.mousePosition.x,Input.mousePosition.y,19);
		
		instance.transform.position = Camera.main.ScreenToWorldPoint(mousePosition);
	}

problem here is I have to click twice. One for the HUD icon and the other for the instantiated object. Can someone help me how to attain the Drag N Drop HUD icon where many games do?

This running on Update right? The problem is:

  • “IsBeingDrag” = false
  • So when you click it will enter the if statement, inside the if statement you set “IsBeingDrag” to True
  • So it will not enter the if statement anymore

Advice:

  • Create an Else statement

  • Move the object there, Because that is when the Boolean is True

  • OR

  • Try to set the Boolean true or false by checking mouse Button press or release

  • if (Input.GetMouseButtonUp(0)) { //Up = Mouse Release}

Good Lucky Buddy