- Home /
How to make a counter in GUI ?
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);
}
}
Answer by AngryOldMan · Apr 19, 2011 at 02:58 AM
http://answers.unity3d.com/questions/17985/pickup-count-on-gui
http://answers.unity3d.com/questions/33757/count-on-collision
http://answers.unity3d.com/questions/37604/counting-on-unity-iphone
these contain the information that you need to complete this task
Answer by M Poirot · May 09, 2011 at 03:57 PM
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;
}
Answer by NewUnityUser · May 15, 2011 at 05:32 AM
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
Answer by XxRobsenxX · Jun 22, 2012 at 09:57 AM
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; }
Answer by any one · Nov 12, 2012 at 02:48 AM
how to make collosion and make counter gui between cube and fpc