- Home /
Question by
mbhigham · Dec 13, 2016 at 07:34 AM ·
javascriptscorescore systemjavascripting
Reset score to 0
I can't figure out what is wtong with my code, I wan't the score to reset when I collide with a specific tag but nothing happens? How can I do this with javascript.
pragma strict
static var score : int = 0;
var scoreText : UnityEngine.UI.Text;
public var impact : AudioClip;
function OnTriggerEnter2D(other : Collider2D)
{
if (other.gameObject.CompareTag("Player"))
{
GameObject.Find("CoinPickUp").GetComponent.<AudioSource>().PlayOneShot (impact, 1.0F);
//audio.PlayOneShot(impact, 0.7F);
Destroy( gameObject);
score += 1;
}
}
function OnColliderEnter2D (coll : Collision2D)
{
if (coll.gameObject.CompareTag("water"))
{
score = 0;
}
}
function OnGUI ()
{
scoreText.text = "" + score;
}
Comment
I think you just have a syntax error
it's supposed to be
OnCollisionEnter2D
You have OnColliderEnter2D, which I don't think is a thing... unless it's different for Javascript
Answer by Gaming-Dudester · Dec 13, 2016 at 07:59 AM
Put a print line above the "score = 0;" line to see if its a problem with the int.
print ("test");
Your answer
Follow this Question
Related Questions
Score system is not working properly, help? 3 Answers
Why cant I subtract point from my score? 1 Answer
How I can find the complete event of my animation 1 Answer
script woe adding score 1 Answer
Use Sprites as Score 1 Answer