Hello guys! I can’t make my car steer. On the computer it runs ok with those Input.GetAxis, but I can’t make it work on the android device. What should I change in this code to make it run on phone? Also what is a substitute for Input.GetAxis for android, because it doesn’t seem to be working on phone.
Thanks in advance!
var maxTorque : float = 200;
var speed:float=3;
var GasTouch : int = 0;
var Steer : int = 0;
var BackLeft : WheelCollider;
var BackRight : WheelCollider;
var FrontLeft : WheelCollider;
var FrontRight : WheelCollider;
var LeftButton : GUITexture;
var RightButton : GUITexture;
var GasButton : GUITexture;
var Joystick : GUITexture;
function Awake()
{ Joystick = GameObject.Find("Joystick").guiTexture;
LeftButton = GameObject.Find("LeftButton").guiTexture;
RightButton = GameObject.Find("RightButton").guiTexture;
GasButton = GameObject.Find("GasButton").guiTexture;
}
function Update()
{
BackLeft.motorTorque=-maxTorque * Input.GetAxis("Vertical");
BackRight.motorTorque=maxTorque * Input.GetAxis("Vertical");
//FrontLeft.steerAngle=20 * Input.GetAxis("Horizontal");
// FrontRight.steerAngle=20 * Input.GetAxis("Horizontal");
for (var touch : Touch in Input.touches)
{
if (touch.phase == TouchPhase.Stationary && GasButton.HitTest (touch.position)) {
GasTouch = 1;
}
else if (touch.phase == TouchPhase.Ended && GasButton.HitTest) {
GasTouch = 0;
}
if (touch.phase == TouchPhase.Stationary && LeftButton.HitTest (touch.position)) {
Steer = -1;
FrontLeft.steerAngle = -15.0;
FrontRight.steerAngle = -15.0;
}
else if (touch.phase == TouchPhase.Ended && LeftButton.HitTest){
Steer = 0;
FrontLeft.steerAngle = 0;
FrontRight.steerAngle = 0;
}
if (touch.phase == TouchPhase.Stationary && RightButton.HitTest (touch.position)) {
Steer = 1;
FrontLeft.steerAngle = 15.0;
FrontRight.steerAngle = 15.0;
}
else if (touch.phase == TouchPhase.Ended && RightButton.HitTest){
Steer = 0;
FrontLeft.steerAngle = 0;
FrontRight.steerAngle = 0;
}
}
if(GasTouch!=0)
{
transform.Translate(Vector3.forward*speed/100);
}