- Home /
2d platformer, coding coin collectable?
So I want to create a system of coins that the player can collect, and even may need to collect x amount to proceed to next scene. So far I have a coin script and coin GUI of the amount collected. They don't seem to work when I apply it to a cube or 'coin'.
here is the script(s);
function OnTriggerEnter(hit : Collider){
if(hit.gameObject.tag == "Game Controller"){
ScoreSystem.myScore += 1;
Destroy(gameObject,0.0);
}
}
and
static var myScore = 0;
var DelayTime = 10;
function Start(){
myScore = 0;
Invoke("myFunction", DelayTime);
}
function OnGUI(){
GUI.Label(Rect((Screen.width / 2) + 20,10, 200, 30), "Coins: " + myScore);
}
what am i doing wrong? I'm new to coding and unity.
The tag is usually called GameController without spaces. Does it get through the if statement of your OnTriggerEnter?
Yeah, I just fixed that as I was pre reading the post. Now I can destroy the object upon collision, but my GUI or "ScoreSystem" just disappears...
Your answer
Follow this Question
Related Questions
Accessing local system ( File Browser ) 2 Answers
animation 2d platformer 2 Answers
jittery jumping 2D character 0 Answers
switching between different screen boxes 2 Answers
2D Buttons 1 Answer