Score system not working at all
Hi guys.
I tried to incorporate a simple coin based scoring system in my game using a script I found in the unity community. I have added the following script to the player object.
#pragma strict
var score = 0;
var scoreText = "Score: 0";
function OnTriggerEnter( other : Collider ) {
Debug.Log("OnTriggerEnter() was called");
if (other.tag == "Coin") {
Debug.Log("Other object is a coin");
score += 1;
scoreText = "Score: " + score;
Debug.Log("Score is now " + score);
Destroy(other.gameObject);
print (score);
}
}
function OnGUI () {
GUI.Label (Rect (1200, 0, 100, 50), scoreText.ToString());
}
Problem is that the console doesn't register anything at all. The score remains zero even if the player object passes through the coins. The coins are not destroyed either.
I have checked the coin tag. I am using polygon collider for the player and circle collider for the coins. The coin collider is set as "is trigger" while player collider is not set so. I have tried changing collision detection settings on player as well but nothing seems to work.
Any ideas where I'm wrong?
i guess you have a 2D project . if so use
OnTriggerEnter2D(other: Collider2D){
if (other.gameObject.tag == "Coin")
}
Your answer
Follow this Question
Related Questions
Score on collision only updates once 1 Answer
2D Object Pickup - Occasionally adding score twice 0 Answers
How can I make an object moving on its own bounce off walls 1 Answer
Turret not spawning fireball via instantiation in Unity 2d? 0 Answers
How to kill player (and or end game) when enemy hits the ground? JAVASCRIPT 1 Answer