- Home /
scoreboard problems
im trying to create a scoreboard but i got a lot of error here is my code
function Update () {
function OnControllerColliderHit(hit : ControllerColliderHit);
var score : GameObject;
if(myCollision.gameObject.name == "fruit")
score.GetComponent("Score").AddToScore();
Destroy (gameObject);
}
i want when my player hit the gameodject fruit get one point but i got error
There are a number of things wrong with this script. I would recommend taking the time to go through a few scripting tutorials before plunging right into things. It will help in the long run.
For a good list of tutorials (though the list is a little dated now), check out this answer.
1st you probably dont want it in the update, that means it's getting fired off many times per second.
Check this out... http://unity3d.com/support/documentation/ScriptReference/Collider.OnCollisionEnter.html
...and see if it helps.
can u fixe my code ChirsD to see what i did wrong please i will help me
No, I'm not going to write your code for you. I've kindly recommended a set of tutorials - try google for more. It's clear that you're new to scripting, and that's good, but you need to learn some basics before any code we write will actually benefit you. I wish you luck.
Ok, thank you for your suggestions and for taking an interest in my learning. I will continue to wait for an answer, but I have taken your comments under advisement.
Answer by Dreamblur · Jun 20, 2011 at 11:04 PM
Remove the semi-colon at the end of the line containing OnControllerColliderHit.
Where is myCollision getting initialized?
EDIT: And what is Update doing on top of the code?
EDIT2: I'm lost. Is that 2 functions mashed up together? XD
i don't really know i just edit a example of a scoreboard that i found in google lol if u fixe it it will help me
Answer by Chris D · Jun 20, 2011 at 11:58 PM
You need to use OnCollisionEnter() in conjunction with GameObject.Tag and, presumably, some GUI shenanigans. I'm not going to write your code for you (and I don't necessarily speak for everyone here) but I will help you if you have specific questions about things and are willing to put some effort in.
You won't understand what your code does until you try to learn it.
Good to hear! The convention on this site is to accept the answer that you use (the check box next to the vote up/down buttons) so that others with similar issues can see that there's a valid solution. Good luck with your project.
Answer by mangohack · Jun 21, 2011 at 11:38 AM
thankyou very muchhhhhhhhhhhh lol i fixed it look at my code
var score : GameObject;
function OnControllerColliderHit(hit : ControllerColliderHit) {
if(hit.gameObject.tag == "Floor")
score.GetComponent("Score").AddToScore();
}
but know i want to know how to create a function Kill () that when my player hit the floor disappear.
Your answer
Follow this Question
Related Questions
Making a scoreboard with a timer 2 Answers
No proper Update and function call between objects ? 1 Answer
I want to know how to save high score. 1 Answer
Save User Score On Cloud, And Showing LeaderBoard According To These Scores 3 Answers
GooglePlayGames Scoreboard doesn't display when called 0 Answers