Ok so, i’m trying to write a script to attach to a first person controller, so that When i walk in to a cube, the cube will disappear and my Score will increase by 5 or 10 or Anything, I have this but something is wrong, i’m a newb at scripting so go easy
var ScoreCounter = 0;
function Update () {
function OnTriggerEnter(){
ScoreCounter += 1;
}
}
function OnGUI () {
GUI.Box (Rect (1,1,200,30), "Score");
}
Thank you!, but i am getting messages saying “Unexpected token: (” and 2 " ‘;’ expected. Insert a semi colon at the end" messgaes, but i can’t see what it is talking about, Any idea?
Edit: also
"Script error: OnCollisionEnter
This message parameter has to be of type: Collision
The message will be ignored.
"
Edit again: It seems that the only error i am now getting is “expecting (, found ‘OnTriggerEnter’.”
The reason your script isn’t working properly is because it’s a bit of a mess, but not to worry it’s easy to fix!
var ScoreCounter = 0;
function OnTriggerEnter(collision : Collider ) {
ScoreCounter += 1;
Destroy(collision.gameObject);
}
function OnGUI () {
GUI.Box (Rect (1,1,200,30), "Score" + ScoreCounter);
}
And that should do the trick. Note that I’m presuming this script is attatched to your player.
The main error in this case was that you’ve declared your OnTriggerEnter function inside your Update, functions can’t be declared in other functions.