- Home /
How to make a startline and finishline? I'm making a car game. Help me.!!
I have a simple carController script. I want to display some UI text like ready steady go! and when go text is display and gone. Player car and AI car can run. And when cars reached the finishline car automatically stopped running. How to do it.
//CarController1.js var wheels : Transform[];
var enginePower=150.0;
var power=0.0; var brake=0.0; var steer=0.0;
var maxSteer=25.0;
function Start(){ rigidbody.centerOfMass=Vector3(0,-0.5,0.3); }
function Update () { power=Input.GetAxis("Vertical") enginePower Time.deltaTime 250.0; steer=Input.GetAxis("Horizontal") maxSteer; brake=Input.GetKey("space") ? rigidbody.mass * 0.1: 0.0;
GetCollider(0).steerAngle=steer;
GetCollider(1).steerAngle=steer;
if(brake > 0.0){
GetCollider(0).brakeTorque=brake;
GetCollider(1).brakeTorque=brake;
GetCollider(2).brakeTorque=brake;
GetCollider(3).brakeTorque=brake;
GetCollider(2).motorTorque=0.0;
GetCollider(3).motorTorque=0.0;
} else {
GetCollider(0).brakeTorque=0;
GetCollider(1).brakeTorque=0;
GetCollider(2).brakeTorque=0;
GetCollider(3).brakeTorque=0;
GetCollider(2).motorTorque=power;
GetCollider(3).motorTorque=power;
}
}
function GetCollider(n : int) : WheelCollider{ return wheels[n].gameObject.GetComponent(WheelCollider); }
Answer by shakecaine · Nov 25, 2017 at 02:40 PM
Create two empty gameobjects representing start and finish. Add colliders to them like for example BoxCollider and make them triggers. Use OnCollisionEnter to detect collision with your car and execute functions to handle the rest of what is supposed to happen. Here you have reference to the script manual: https://docs.unity3d.com/ScriptReference/Collider.OnCollisionEnter.html?_ga=2.5525685.747375645.1511525148-435282229.1502711943
@shakecaine Thanks for replying me. Your answer is O$$anonymous$$! But I add some "ui text" to the scene and have the text:Ready s$$anonymous$$dy Go! And I want that when the UI text is over, when my race starts. how to do it?
If you want "Ready, S$$anonymous$$dy, Go!" then i propose you to use Coroutines. As you could do Ready and wait 1/2 second, S$$anonymous$$dy and so on and after just unlock controls for the car. In the coroutine you just change text of the UI.
Your answer
Follow this Question
Related Questions
Better RPM?? 0 Answers
Problem with cars in Unity 5 0 Answers
How add kilometre per hour system in car script,how to add kilometre per hour speed system in script 0 Answers
Car Physics 0 Answers
2D Car problem with motor 0 Answers