- Home /
Pls. Help how can I convert this script to be press using UI buttons. I want the vertical to be pressed and the for the horizontal I will make 2 arrows left and right. Thank you in advance
using UnityEngine; using System.Collections; using System.Collections.Generic;
 [System.Serializable]
 public class AxleInfo {
     public WheelCollider leftWheel;
     public WheelCollider rightWheel;
     public bool motor;
     public bool steering;
 }
  
 public class SimpleCarController : MonoBehaviour {
     public List<AxleInfo> axleInfos; 
     public float maxMotorTorque;
     public float maxSteeringAngle;
  
     // finds the corresponding visual wheel
     // correctly applies the transform
     public void ApplyLocalPositionToVisuals(WheelCollider collider)
     {
         if (collider.transform.childCount == 0) {
             return;
         }
  
         Transform visualWheel = collider.transform.GetChild(0);
  
         Vector3 position;
         Quaternion rotation;
         collider.GetWorldPose(out position, out rotation);
  
         visualWheel.transform.position = position;
         visualWheel.transform.rotation = rotation;
     }
  
     public void FixedUpdate()
     {
         float motor = maxMotorTorque * Input.GetAxis("Vertical");
         float steering = maxSteeringAngle * Input.GetAxis("Horizontal");
  
         foreach (AxleInfo axleInfo in axleInfos) {
             if (axleInfo.steering) {
                 axleInfo.leftWheel.steerAngle = steering;
                 axleInfo.rightWheel.steerAngle = steering;
             }
             if (axleInfo.motor) {
                 axleInfo.leftWheel.motorTorque = motor;
                 axleInfo.rightWheel.motorTorque = motor;
             }
             ApplyLocalPositionToVisuals(axleInfo.leftWheel);
             ApplyLocalPositionToVisuals(axleInfo.rightWheel);
         }
     }
 }
               Comment
              
 
               
              Your answer
 
 
             Follow this Question
Related Questions
UI works in editor, but not on mobile device 1 Answer
UI button shows in editor but not on mobile? 0 Answers
Button Navigation none - not working with touchscreen 0 Answers
[5.4 - Unity2D - Android] UI Button Requires Child Text? 0 Answers
How to make Input.GetAxis work on certain area only? 0 Answers
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                