The lap system works by 3 waypoints set along the track (a waypoint being a cube with an attached box collider as a trigger). When the car collides with a waypoint, a boolean value connected that waypoint is set to true. Once all waypoints have been activated, the number of laps is increased by 1 and all booleans are set back to false. I've added the code below:
The main diffulty I noticed is that most of the code for Unity is written in Javascipt. While I know C# (which is supported in unity), C++ and Java, there are quite a few methods in Java which I need to keep looking up to find out how to run that particular method (in this case, the OnTriggerEnter method). Converting this code into C# would take too much time so its slightly difficult writing new bits of code in a language I am not perficient in. Hopefully, this won't delay my scedule too much, but it is yet another thing I did not account for in my planning.
var Waypoint0Col = false;
var Waypoint1Col = false;
var Waypoint2Col = false;
static var NoLaps = 0;
function OnTriggerEnter(other : Collider)
{
if(other.gameObject.name == "Waypoint_0"){
Waypoint0Col = true;}
if(other.gameObject.name == "Waypoint_1"){
Waypoint1Col = true;}
if(other.gameObject.name == "Waypoint_1"){
Waypoint2Col = true;}
if(Waypoint0Col == true && Waypoint1Col == true && Waypoint2Col == true){
NoLaps += 1;
Waypoint0Col = false;
Waypoint1Col = false;
Waypoint2Col = false;
}
}
No comments:
Post a Comment