- Home /
Ending game after finishing chekpoint
hello, i have been following the race track tutorial, from unity by Morten Sommer, and making a racing game in my neighborhood 3d, addis ababa, Ethiopia.
i have set up the basics and it works perfectly. I added checkpoints and managed to pass through them and display the remaining checkpoints left,play a little pop sound at pick up. using info on this site.
what i couldn't manage to do was having it switch level when the counter reach zero. i tried some of the solutions in here but didn't seem to work. Here is the code i'm using. i hope you guys will help and point me in the right direction. tnx
var skin:GUISkin;
var CheckPoint;
var PickUpSound: AudioClip;
var BackgroundMusicVolume : float = 0.6;
function OnTriggerEnter( other : Collider )
{
if (other.tag == "Finish")
{
CheckPoint -= 1;
AudioSource.PlayClipAtPoint(PickUpSound,Camera.main.transform.position);
volume = BackgroundMusicVolume;
Destroy(other.gameObject);
}
}
function Awake()
{
CheckPoint = 3;
}
function OnGUI()
{
GUI.skin = skin;
GUI.Label( Rect (Screen.width - (Screen.width)/3.5,50, 300, 45),"CheckPoint = " + CheckPoint );
}
function update()
{
if ( CheckPoint == 0)
{
Application.LoadLevel("1");
}
}
Answer by syclamoth · Sep 13, 2011 at 11:01 AM
Simplest solution- Application.LoadLevel() can be used with either a string or an int. If you call it with a string (like you are doing here), it will look for the level named "1" and try to load that, which of course will not work (unless you actually called your level that). What I prefer to do for this kind of thing, is call Application.LoadLevel(0), which is guaranteed to work (seeing as level 0 will always exist). Try that and see how far you get.
Hope this helps!
Answer by japanitrat · Sep 13, 2011 at 10:36 AM
You need to capitalize Update(), because "update()" is not called by Unity (but "Update()" is).
Answer by ighazali · Oct 01, 2011 at 02:44 PM
As I promised. I added the credits and you can download the game :
Your answer
![](https://koobas.hobune.stream/wayback/20220612211858im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Racing Game - setting up a car TIRES 1 Answer
Best Packages to Make Online Car Race Game 0 Answers
Race checkpoint system small help please :) 1 Answer
How can I create a single car with different settings? 0 Answers
Arcade car phisics 1 Answer