- Home /
Other
how to do car ranking system on finish line
i am making a car game. i have completed all the things but stuck in ranking system.All i want is when the player hits the finish line collider , then it will display a panel on which all the ranking of four cars are written. thanks.
Answer by Padalino · Aug 16, 2016 at 05:02 PM
You could try to create a Canvas that will display the cars. That Canvas would have 4 children texts (Pos1Text,Pos2Text and so), and you will also need a script to check which car arrives. Then in the finish line, when the car A hits the collider, the Pos1Text would change its value to carAname. Then set the Pos1Text.enabled to true. I.e. void OnCollisionEnter (Collision col) { if (col.tag == "Car1" && currentcar == 1) { Pos1Text.enabled = true; Pos1Text.text = " Car1 "; Currentcar + +; } else if ( col.tag = = " Car1 " & & currentcar = = 2 ) / / same that above, but using Pos 2 values. Else the same using Pos 3 values. That should be repeated with the 4 cars
No need for so many IFs if you do something like...
Text[] labels; //drag ranking text fields here in inspector
List<string> carNames = new List<string>();
void OnCollisionEnter (Collision col) {
carNames.Add(col.name);
var i = 0;
foreach (var label in labels) {
label.text = i < carNames.Count ? carNames[i++] : "";
}
}
thanks nosekills but array is little bit confusing for me because i am new to unity but i will try it
I knew there was an easier way to accomplish that, but since I'm a bit new to all of this, using if statements was the easiest way to do it for me (it's easily comprehensive). I'll have Nosekills' answer into account if I need to do something similar in the future. Everyday we can learn new things ;)
Follow this Question
Related Questions
drift car using rigidbody 1 Answer
How add kilometre per hour system in car script,how to add kilometre per hour speed system in script 0 Answers
car game questions 1 Answer
A game like Need For Speed? 1 Answer
Car Positioning System 0 Answers