- Home /
Make an object move when clicking a GUI button?
How do I make an object move when I click a GUI button? I want it to move to the left when I click it.
This is a little slim, you need to narrow down a little what you want. Also, have you been trying something already? That would help in knowing the type of code you can be given.
I'm making an Android game where you tap a GUI button to move the player to the left, and another to move the player to the right.
Answer by ODNSEV7N · Nov 23, 2013 at 08:30 AM
A fairly simple example here :)
Moves the object/s in increments of 10. (Or whatever you decide)
http://docs.unity3d.com/Documentation/ScriptReference/Transform.html
Or this may work (just moving a selected Object)
var objectToMove : Transform;
function OnGUI (){
if(GUI.Button(Rect(110, 155, 300, 100),"MOVELEFT")){
objectToMove.position += Vector3.left* 10.0;
}
}
Your answer
Follow this Question
Related Questions
How do I make a cube teleport after dropping below a point? 1 Answer
About ListItems in Unity3D 1 Answer
Unity editor style camera script 1 Answer
Flying AI Planes 0 Answers
Android Plugin Help 1 Answer