- Home /
int count on collision enter not working
public var touchCount : int;
function Update()
{
if (touchCount >= 4)
renderer.material.color = Color.red;
if (touchCount < 4)
renderer.material.color = Color.gray;
}
function OnCollisionEnter ()
{
touchCount + 1;
Debug.Log ("+ 1");
}
function OnCollisionExit ()
{
touchCount - 1;
Debug.Log ("- 1");
}
Answer by hd27 · Dec 08, 2013 at 04:05 PM
it should be: touchCount++ or touchCount += 1
no its not workin, i mean it builds correctly but it doesn't work in real
try to put the script in a cube and let other cubes touch it and it will not count at all
You need to pass the colliders into the OnCollision function try:
function OnCollisionEnter (coll : Collision){
if(coll.transform){
touchCount++;
}
}
Now when the cubes will cillide the function takes the collision event and if the object that we cillided with has a transform touchCount will increment;
Your answer
Follow this Question
Related Questions
script trying to access a null gameobject's collider... can't fix 2 Answers
Go To new Scene Button! 1 Answer
On Trigger Enter, Collide with object, specific collision 1 Answer
Collision Only being detected on one of the objects involved in the collision - C# 0 Answers
Colliding two GameObjects 1 Answer