Button not working

Hello. im programming for iPhone and i find that for placing a button to the screen i must use this code

function OnGUI () {
	if (GUI.Button (Rect (10,10,150,100), "I am a button")) {
	
	}
}

The button shows correctly. Now i want that an object move when the button is pressed, so i replaced code for this one

var speed = 5,0;
function OnGUI () {
	if (GUI.Button (Rect (10,10,150,100), "I am a button")) {
		
	var x = Input.GetAxis("Horizontal") * Time.deltaTime * speed;
	var z = Input.GetAxis("Vertical") * Time.deltaTime * speed;
	transform.Translate(x, 0, z);
	}
}

But nothing happens. Can someone help me?

Thanks

There isn’t a Horizontal or a Vertical axis on the iPhone, as those things are tied to mouse or keyboard input, so they will always return 0. If you meant for that to be using the accelerometer, use iPhoneInput.acceleration.

–Eric

Thanks, now another question. I am in this moment using this code and is working

function Update () {
	
}

function OnGUI () { 
   if (GUI.Button (Rect (10,10,150,100), "I am a button")) { 
   var z = iPhoneInput.acceleration.z * -1;
	transform.Translate (0,0,z);
		
	var x = iPhoneInput.acceleration.x;
	transform.Translate (x,0,0);
	}
}

The problem is the object just moves when the button is pressed one time, and the user must release the button and press it again to keep moving

How can i make the object move constantly when the user HOLDS the button?

Thanks

There’s GUI.RepeatButton.

–Eric

Thanks

Oh, i forgot the last question. How can i make the camera move at the same time the object moves?

The easiest way is to make the camera a child of the object.