- Home /
Score Counter Help
Ok so here is my score counter script to put on a GUI Text
function OnGUI(){
guiText.text = "Score: "+CubeScript.Counter;
}
i want it so that when i collide with a cylinder it goes up by 10 so i have this script but it is not working
static var Counter : int = 0;
function OnCollisionEnter (myCollision : Collision)
{
if(myCollision.gameObject.name == ("Cylinder"))
{
Counter++;
}
}
Hey, Ill need bit more information about where and how you're trying to impelement this. Is it all on the same object?if not do you reference the cubescript correctly? Also try to indent you code so is more readable and paste it using the 101010 button so its nicely formatted in you're question.
Cheers!
Like Vin said, we need a little more information about your code before we can help...
o sorry the 2 scripts are seperate the GUI goes in a GUItext in a GameEmpty same as the object i am colliding with,then the cube script is to go onto the player because it's for mycollision. thanks alot (the only way i got the GUI to show up is if i put it in a GameEmpty)
@conflictbliz please stop adding comments as answers; it's now non-trivial to look through this thread and see where things stand. In the future, either edit your original question or comment on it if you have clarifications to make.
Additionally, by deleting all your below comments and putting their details into your original question, you can make it readable (and more likely to have attention paid to it) once more.
please stop adding comments and other questions as answers.
Answer by Jaywalker · Jul 22, 2011 at 06:20 AM
Hey,
I cannot check it right now but try this:
on the trigger (for example a box collider with the trigger boolean turned on)
function OnTriggerEnter(other : Collider)
{
if(other.tag == "the tag for your player object")
{
GuiScript.Counter += 10;
}
}
And in your gui script (named GuiScript.js):
static var Counter : int;
function OnGUI()
{
GUI.Label (Rect (10, 10, 100, 20), "Score: " + Counter);
}
Answer by crazyKnight · Jul 21, 2011 at 05:13 AM
firstly it wont be counter++
as you want the value to go up by 10 it will be counter+10
and to check the collision instead of checking with name its better you tag the cylinder and then check it
function OnCollisionEnter(myCollision : Collision)
{
if(myCollision.gameObject.tag == "the name with which you tagged cylinder")
counter+=10;
}
Your answer
Follow this Question
Related Questions
Score/point counter system 1 Answer
GUI Text Score counter 3 Answers
GUI.box (Score counter) doesn't appear when game is on play. 1 Answer
Score count increase on hit 2 Answers