Quantcast
Channel: Latest Questions on Unity Answers
Viewing all articles
Browse latest Browse all 171066

OnCollisionEnter doesn't work

$
0
0
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; }

Viewing all articles
Browse latest Browse all 171066

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>