- Home /
Duplicate Question
Load level on collision if player has certain score
I have a simple game, where there is a cannon which shoots out a ball, and the aim is to collect the coins with this ball, and land on the exit platform (which will load a new scene).
I have my different functions in various scripts, e.g. lives, shooting the ball from the cannon & scoring system.
Problem is, I'm stuck on making the exit platform. I was planning to use something like onCollisionEnter, Application.LoadLevel, with an if else statement, so if the score is above 3, then load next level, but if the score is under 3, then load the gameover screen. However, as all my scripts are separated, when I try to do this, I dont know how to call in the score to check if the Counter = 3.
Is there any way that code could be added to the scoring system scripts so it can check for the collision (between ball and exit gameObjects, as it will then be able to check that the Counter = 3.
These are my scoring scripts: This is attached to my GUI text: var Counter : int = 5; var pointsNeeded : int;
function Update () {
guiText.text = "Score : "+Counter;
}
and this is attached to the coins in the scene:
function OnCollisionEnter(myCollision : Collision){
if(myCollision.gameObject.name == "ball"){
Destroy(gameObject);
gameObject.Find("Score").GetComponent(scoreCounter).Counter+=1;
}
}
If anyone could help that would be great! Thanks in advance.
this would have to be the most common question on this site
http://docs.unity3d.com/Documentation/ScriptReference/index.Accessing_Other_Game_Objects.html
http://docs.unity3d.com/Documentation/ScriptReference/index.Accessing_Other_Components.html
unityGE$$anonymous$$S.com
Also if you need a timer, it is Invoke()
Hope it helps!
Follow this Question
Related Questions
Double If condition syntax ? 1 Answer
OnTriggerEnter to load new level 1 Answer
If Statement Conditional Not Working 1 Answer