Hi. I have a sphere gameobject with a sphere collider, mesh renderer, rigidbody. Then i have a cube gameobject with a box collider, mesh renderer, rigidbody, my script attached to it as well.
I have some gui text, everytime the sphere collides with the cube i want a variable called points to be incremented. Here is my script, i dont understand why it isn't working, everytime the sphere hits the cube, the gui text remains: points 0. thanks for any help.
var points: int;
var refText: GameObject;
function Start ()
{
points =0;
refText.guiText.text="Points: "+points;
}
function OnCollisionEnter(collision : Collision)
{
if(collision.gameObject.tag=="myCubes")
{
Debug.Log("Ball hit Box");
points++;
}
}
function Update ()
{
refText.guiText.text="Points: "+points;
}
↧