- Home /
Switch Levels After Getting A Score?
I have a simple script that you attach to a trigger and when you run into it you switch levels and I also have coins in my game that make it so you get points. What I want to do is make it so the trigger (cube) only appears after you have at least say 20 coins. I know this is a simple question but I can't figure it out. Thank You!
Answer by DryTear · Feb 03, 2013 at 03:27 AM
attach this script to your coin and tick its Trigger checkbox in the Collider settings
var points : 0;
var TargetPoints : int;
function OnTriggerEnter(col : Collider){
if(col.gameObject.tag == "Player")
{
points++;
}
}
function Update(){
if(points = TargetPoints)
{
GameObject.FindWithTag("FinishPoint").collider = true;
}
else
{
GameObject.FindWithTag("FinishPoint").collider = false;
}
}
The trigger that loads level must have a tag "FinishPoint"
This wont work, points is a local variable for each script on each coin and never exceeds 1.
Answer by Vonni · Feb 03, 2013 at 03:36 AM
Hey there youngster! You could could use a script that holds global variables for you.
Create a new script and name it "GameTracker"
(or something)
create a STATIC variable in this script
static var coins : int; // Thats all you need in this script
now in that script you got on your coins. Somewhere in that script before it gets destroyed, call these lines:
GameTracker.coins++;
if(GameTracker.coins == 20){
// Enable Trigger
}
Your answer
Follow this Question
Related Questions
How do I make it so that when you pass over a line, you switch levels? 3 Answers
2D Coins and Points 1 Answer
How to make collectibles 2 Answers
Second coin is destroyed when i touch the first one 1 Answer