system
April 19, 2011, 2:37am
1
Hey guys. I need help to make a count on GUI.Text
Each time that I shot in an Target it be destroyed and de count marks 10 points for example...
I have a code here but i dont know how to put the score in this code.
This make the targe be destroyed, how I do to count scores ?
function OnCollisionEnter (hit : Collision)
{
if (hit.gameObject.tag == ("target"))
{
GameObject.Destroy(hit.gameObject);
}
}
5 Answers
5
I think the following will do,,
static var score : int = 0;
function OnCollisionEnter (hit : Collision){
if (hit.gameObject.tag == ("target")){
GameObject.Destroy(hit.gameObject);
score += 10;
}
}
if you want this score to be shown in a GUitext add the following script to the GUI
function OnGUI(){
guiText.text = "Score: "+codeNameForDestructionAndScoreCountingHere.score;
}
M Poirot- What do I replace "codeNameForDestructionAndScoreCountingHere" with? I've tried several things but they don't work. The rest of your script is great.
Thanks
system
June 22, 2012, 9:57am
5
You have to replace the “codeNameFor…” with the Script of the Collision ( where you write the line “score+=10;”
For Example:
function OnGUI(){
guiText.text = "Score: "+Controller.score;
}
any_one
November 12, 2012, 2:48am
6
how to make collosion and make counter gui between cube and fpc