Unity to Unity Iphone Migration Question RE OnGUI Command

Hi guys, I need a little help with moving from unity to unity iphone. I have a script that moves a cannon barrel along just the 1 axis. Works great in normal unity.

var turnSpeed = 5; 
var moveSpeed = 5;  


private var y : float; 
function Update () 
{  
   // check to see if the W or S key is being pressed.  
   y = Input.GetAxis("Vertical") * Time.deltaTime * moveSpeed; 
    
   // Move the character forwards or backwards 
   transform.Rotate(y, 0, 0); 
          
}

I want to just use two different OnGUI buttons to move it up or down.

I made a nice fire button earlier today that works well using OnGUI.
Here it is for anyone else who needs it. (the velocity is controlled via a slider bar).

var mypeepsPrefab : Rigidbody;
var throwClip : AudioClip;
var reloadTime = 0.5;
static var Count = 50;
private var LastShot = -10.0;
private var fired : boolean = false; 
 

function OnGUI() { 
	 if (GUI.Button(Rect(Screen.width-75, Screen.height-70,50,50),""))
     fired = true; 
} 


function Update () {
		if (fired  (Time.time > reloadTime + LastShot  Count > 0))	{
			fired = false;
							
			var peeps : Rigidbody = Instantiate(mypeepsPrefab,
transform.position, transform.rotation);
			peeps.velocity = transform.TransformDirection(Vector3
(0,0,SliderBar.vScrollbarValue));
			
			Physics.IgnoreCollision(peeps.collider,
transform.root.collider);
			audio.PlayOneShot(throwClip);
			
			LastShot = Time.time;
			Count--;
	}
}

So any ideas how to convert the code at the very top using OnGUI into unity iphone much appreciated :wink:

I am assuming that you are worried about having constant input from a pressed button, rather than the ‘one shot’ input of a detected button press?

If so, a quick peek at the doc’s (search == OnGUI; refined search == GUI.button) reveals:

file:///Applications/Unity%20iPhone/Documentation/ScriptReference/GUI.RepeatButton.html

GUI.RepeatButton:
Description
Make a button that is active as long as the user holds it down.

Beware that OnGUI and GUI.x can be inefficient on the iPhone. Search the forum for alternative solutions, including SpriteManager, GUIManager and SpriteUI.

Hey thanks for that, after a fair bit of trial and error I have come to the conclusion also that OnGUI was too heavy for iphone use. It made a noticeable impact on performance. A pity but if it is checking all the time for input I guess thats not noticed on a normal PC.

I have pulled apart the Occlusion demo to see how the gui texture and touch inputs work. Its certainly a bigger learning curve than OnGUI. But I will persist. I am think about creating another post relating to that and construction of a nintendo game and watch like control set.