Steer Vehicle on Button Press New Unity UI

Hello Guys,

I’m trying to steer my car with buttons that I just created using Unity UI introduced in 4.6. I’m not sure what I’m doing wrong but Only Left button is working. This is my code.

using UnityEngine;
using UnityEngine.EventSystems;

public class PlayerManuever : MonoBehaviour,IPointerDownHandler ,IPointerUpHandler
{
    private bool _isPressed;

    public WheelCollider WheelFL;
    public WheelCollider WheelFR;

    public float MaxSteer;
    public float TurnSpeed;
    public float TurnValue;

    public string ButtonName;  // Provided name from the Inspector. Left or Right


    void Awake()
    {

        WheelFL = GameObject.FindGameObjectWithTag(Tags.frontLeftWheel).GetComponent<WheelCollider>();
        WheelFR = GameObject.FindGameObjectWithTag(Tags.frontRightWheel).GetComponent<WheelCollider>();
    }
	// Use this for initialization
	void Start () {
	
	}
	
	// Update is called once per frame
	void Update () {
	    if (_isPressed)
	    {
	        switch (ButtonName)
	        {
	            
	            case "Right":
	                if (TurnValue < 1)
	                {
	                    TurnValue = TurnValue + TurnSpeed*Time.deltaTime;
	                }
	                WheelFL.steerAngle = MaxSteer*TurnValue;
	                WheelFR.steerAngle = MaxSteer*TurnValue;
	                break;
                case "Left":
                    if (TurnValue > -1)
                    {
                        TurnValue = TurnValue - TurnSpeed * Time.deltaTime;
                    }
                    WheelFL.steerAngle = MaxSteer * TurnValue;
                    WheelFR.steerAngle = MaxSteer * TurnValue;
                    break;
	        }
	    }
	    else
	    {
            TurnValue = 0;
            WheelFL.steerAngle = 0; // I'm  pretty sure something is wrong here but couldn't understand
            WheelFR.steerAngle = 0;
	    }
	}

    public void OnPointerDown(PointerEventData eventData)
    {
        _isPressed = true;
    }

    public void OnPointerUp(PointerEventData eventData)
    {
        _isPressed = false;
    }
}

I’ve attached this script to both of my Buttons(Left and Right) . And In inspector I’ve provided the string “Left/Right” in the ButtonName field.

I know it’s a very lame question but as a newbie couldn’t find a way around. Please Help me , Thanks In Advance.

Any reason you can’t just use the Cross Platform Input manager? Seem’s like you are just looking for a positive/negative value on a single axis.

Even if you just want to use your own custom buttons, just create GUI buttons rather than hooking into OnPointerDown and whatnot. MUCH easier to just use the Standard Assets for this.

Hope that helps

Adam