- Home /
How to create a button
Hi, i wanted to create a Button in unity which creat's an object when i press it i tried:
if(Input.touchCount >=1) {
var touch: Touch = Input.touches[0];
if(touch.phase != TouchPhase.Ended && touch.phase != TouchPhase.Canceled) {
Instantiate(basis,pos.position,pos.rotation);}
else {Instantiate(basis,pos.position,pos.rotation);
}
}
}
But with this it doesnt stop creating objects, and it isnt a button at all, would be really thankful if anyone could help me.
Answer by gregzo · Dec 04, 2011 at 10:34 PM
Hi! Surely you've mistyped your script, because as we can read it, it basicaly says: if this, do that, and if not, well... do it as well! No wonder you're instantiating lots of objects.
Answer by Th3R0ck · Dec 05, 2011 at 12:49 AM
Yes I know,but the problem is that I don't know how to stop it, because stop/end don't work.
I tried else {return Instantiate(basis,pos.position,pos.rotation);
but this also wont work.
Answer by wolventoad · Dec 05, 2011 at 04:42 PM
delete this part "else {Instantiate(basis,pos.position,pos.rotation);"
Your answer
Follow this Question
Related Questions
pause and restart button on android 1 Answer
GUI.Button press (not click) 3 Answers
Button Touch for Android 2 Answers
Not Able to see Joystick & Button after deploying game to Android Device 1 Answer
Merge 2 Script Touch 1 Answer