- Home /
I want to move my cube using GUI buttons?
i want to move my cube in a train on Move Front, back, right and Left GUI Buttons by pressing them?
if(GUI.Button(new Rect(#, #, #, #), "Front") {
// Add code for "$$anonymous$$ove Front" here
}
if(GUI.Button(new Rect(#, #, #, #), "Back") {
// Add code for "$$anonymous$$ove Back" here
}
if(GUI.Button(new Rect(#, #, #, #), "Left") {
// Add code for "$$anonymous$$ove Left" here
}
if(GUI.Button(new Rect(#, #, #, #), "Right") {
// Add code for "$$anonymous$$ove Right" here
}
All in OnGUI()
, of course.
thanks for reply, can u also tel me the script for move forward
Answer by hijinxbassist · Jun 18, 2012 at 09:33 AM
If this is on your cube, you can use this version. Otherwise change transform.position to cube.position(if you declaration is : Transform cube)
if(GUI.Button(new Rect(#, #, #, #), "Front") {
transform.position+=transform.forward;
}
if(GUI.Button(new Rect(#, #, #, #), "Back") {
transform.position-=transform.forward;
}
if(GUI.Button(new Rect(#, #, #, #), "Left") {
transform.position-=transform.right;
}
if(GUI.Button(new Rect(#, #, #, #), "Right") {
transform.position+=transform.right;
}
This will move them one gameUnit: (0,0,1) or (0,0,-1) or (-1,0,0) or (1,0,0)
If you want to move them holding the button down you can use RepeatButton.
@nick9629: Could you accept his answer so this question closes?
@$$anonymous$$izuho LOL, somehow i missed the original question and only saw your comment! Didnt mean to jack your post(word for word), thot it was the org at a glance. Thanks for your help previous and your support here, thanks
@hijinxbassist: That's completely awesome xD. Answered the question because you thought my answer was the question xD.
Pretty funny indeed, the question was soo short i skipped right over the question(not usual) and just read the code(normally the first thing i read in a post, after skim$$anonymous$$g the concern)
Your answer
Follow this Question
Related Questions
Control script generated buttons with a Gamepad 0 Answers
How can i design 3d buttons in unity 3d? 1 Answer
On Screen Button Controls 0 Answers
Stuck with sliding GUI panels 0 Answers
Problem with rect and touch 1 Answer