- Home /
car controls gui
I have trouble combining two scripts for iPhone controls. I have script for GUI texture that represents gas pedal, and a script for vehicle control. Realy don't know what to do... I would appreciate any help. Thanks!!!
This is my Gui script
function Update() {
if(Input.touchCount > 0){ var touch : Touch = Input.touches[0];
if(touch.phase == TouchPhase.Began && guiTexture.HitTest(touch.position) )
{
Something goes here...
}
}
}
And this is the vehicle script
var FrontLeftWheel : WheelCollider;
var FrontRightWheel : WheelCollider;
var GearRatio : float[];
var CurrentGear : int = 0;
var EngineTorque : float = 600.0;
var MaxEngineRPM : float = 3000.0;
var MinEngineRPM : float = 1000.0;
private var EngineRPM : float = 0.0;
function Start () {
rigidbody.centerOfMass.y = -2;
}
function Update () {
rigidbody.drag = rigidbody.velocity.magnitude / 200;
EngineRPM = (FrontLeftWheel.rpm + FrontRightWheel.rpm) /2 * GearRatio[CurrentGear];
ShiftGears();
FrontLeftWheel.motorTorque = EngineTorque / GearRatio[CurrentGear] * Input.GetAxis ("Vertical");
FrontRightWheel.motorTorque = EngineTorque / GearRatio[CurrentGear] * Input.GetAxis ("Vertical");
function ShiftGears() {
if ( EngineRPM >= MaxEngineRPM ) { var AppropriateGear : int = CurrentGear;
for ( var i = 0; i < GearRatio.length - 1; i ++ ) {
if ( FrontLeftWheel.rpm * GearRatio[i] < MaxEngineRPM ) {
AppropriateGear = i;
break;
}
}
CurrentGear = AppropriateGear;
}
if ( EngineRPM <= MinEngineRPM ) { AppropriateGear = CurrentGear;
for ( var j = GearRatio.length-1; j >= 0; j -- ) {
if ( FrontLeftWheel.rpm * GearRatio[j] > MinEngineRPM ) {
AppropriateGear = j;
break;
}
}
CurrentGear = AppropriateGear;
}
}
Your answer
![](https://koobas.hobune.stream/wayback/20220613105526im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Touchscreen for unity 2 Answers
rotated GUI behaving differently on iphone and ipad 1 Answer
useGUILayout=false does not honor GUI.depth 0 Answers