Touch controls not working

Hello!

I’ve been making a mobile car game for around 2 months now and I am starting to test the product on my iPhone. This is the first time that I get to try out my touch controls and surprise surprise they aren’t working.

public GUITexture gasButton;
	public GUITexture brakeButton;
	public GUITexture leftButton;
	public GUITexture rightButton;
	public int motorInputTouch = 0;
	public float brakePower = 100;

void Awake ()
	{
		gasButton = GameObject.Find ("Gas").guiTexture;
		brakeButton = GameObject.Find ("Brake").guiTexture;
		leftButton = GameObject.Find ("Left").guiTexture;
		rightButton = GameObject.Find ("Right").guiTexture;
	}

void Update ()
	{
		
		foreach (Touch touch in Input.touches) {
			
			if (touch.phase == TouchPhase.Stationary && gasButton.HitTest (touch.position)) {
				motorInputTouch = 1;
				
			} else if (touch.phase == TouchPhase.Ended) {
				motorInputTouch = 0;
				
			}
			if (touch.phase == TouchPhase.Stationary && brakeButton.HitTest (touch.position)) {
				brakePower = 100;
				
			} else if (touch.phase == TouchPhase.Ended) {
				brakePower = 0;
			}
			
			if (touch.phase == TouchPhase.Stationary && leftButton.HitTest (touch.position)) {
				wheelFL.steerAngle = -10.0f;
				wheelFR.steerAngle = -10.0f;
				
			} else if (touch.phase == TouchPhase.Ended) {
				wheelFL.steerAngle = 0;
				wheelFR.steerAngle = 0;
				
			}
			if (touch.phase == TouchPhase.Stationary && rightButton.HitTest (touch.position)) {
				wheelFL.steerAngle = 10.0f;
				wheelFR.steerAngle = 10.0f;
				
			} else if (touch.phase == TouchPhase.Ended) {
				wheelFL.steerAngle = 0;
				wheelFR.steerAngle = 0;
				
			}
			
		}
}

I couldn’t get the button to show with only the GUITexture component, but adding an image component fixed the issue.

You should definitely use New GUI Buttons. Like real buttons…

It is not that I don’t want to answer you. But to use new UI properly you need to watch this Unity Connect

It is very useful :wink: