x


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++;
   }
}
more ▼

asked Jul 21 '11 at 04:22 AM

conflictbliz gravatar image

conflictbliz
26 14 16 19

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!

Jul 21 '11 at 04:51 AM Jaywalker

Like Vin said, we need a little more information about your code before we can help...

Jul 21 '11 at 05:13 AM AVividLight

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)

Jul 22 '11 at 04:03 AM conflictbliz

@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.

Jul 22 '11 at 06:37 PM Chris D

please stop adding comments and other questions as answers.

Jul 22 '11 at 11:00 PM Chris D
(comments are locked)
10|3000 characters needed characters left

2 answers: sort voted first

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);
}
more ▼

answered Jul 22 '11 at 06:20 AM

Jaywalker gravatar image

Jaywalker
514 15 21 30

(comments are locked)
10|3000 characters needed characters left

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;
}
more ▼

answered Jul 21 '11 at 05:13 AM

crazyKnight gravatar image

crazyKnight
869 16 20 30

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x3698
x274
x101

asked: Jul 21 '11 at 04:22 AM

Seen: 2274 times

Last Updated: Jul 23 '11 at 05:25 AM