- Home /
script error GUI super simple code
var score = 0;
guiText.text = "Score: "+score;
function OnCollisionEnter(hit : Collider) { if(hit.gameObject.name == "bug enemy pre(Clone)"){ { score += 5; } } }
It's pretty straight forward, but basically on collision with the enemy object, I want the score to move up by 5. I'm getting an error that says "Assets/score.js(9,11): BCE0044: expecting :, found '+='." I'm sure this is a super simple error, and I have tried changing some things around, but this seems like the smoothest solution, so a little help would be very much appreciated. oooooo, and anyone who gives an answer (that solves my problem) can call me an idiot! And its JS...
Answer by FLASHDENMARK · Feb 01, 2011 at 09:05 PM
Is this helping ?:
var score = 0;
guiText.text = "Score: "+score;
function OnCollisionEnter(hit : Collision) { if(hit.gameObject.name == "bug enemy pre(Clone)") { score += 5; } }
Not sure if this is fixing it,but you had brackets to many.
Answer by Eric5h5 · Feb 01, 2011 at 09:03 PM
"score ++ 5" isn't valid syntax. "score += 5"
ya that was one of the things i played with, but with that in place i updated the error in the post
Answer by Devlus · Feb 01, 2011 at 09:21 PM
Ok using both of your advice i fixed it to an un-bugged version! thanks... i'm not sure who to mark correct, because you both were right... anyway here is the working code
var score = 0;
guiText.text = "Score: "+score;
function OnCollisionEnter(hit : Collision){ if(hit.gameObject.name == "bug enemy pre(Clone)"){ score += 5; } }
whether this code works or not is for another day, anyway thanks all
Your answer
Follow this Question
Related Questions
I need help with an error 1 Answer
script not working 2 Answers
Script error. Please Help! 4 Answers
BCE0044: expecting ':' found ';' 1 Answer
ShopScript.Js(49,17): BCE0044 expecting :, found GUI. 1 Answer