How to activate a button?

Hi there,

I’m having a problem with my script…
It’s written in javascript and I can’t figure out what’s wrong. I want to have a GUI Button and if I click on it I should be able to place a object in the scene. The instantiating part works fine, with a raycast. But if I add a GUI Button, it instantiates at the moment I click, and only if I click the button, so you can only place object in the button part of the screen…

Is there any way to script it so that you can instantiate if you clicked the button once, and if you click it again, you can’t?

1 Answer

1

bool clickedOnce = false; //global variable for that script

//if GUI button clicked
if(!clickedOnce){
   //Instantiate object
   clickedOnce = true;
}

Are you saying that you want to click the button, then click again to place the building where you want it?

Exactly, ;)

I get your way of thinking, but it does exactly the same as my script. It only creates a object in the button part of the screen

change to Input.GetMouseButtonDown(0) that should get the next click, if im not mistaken