- Home /
How can I find amount of objects, colliding with other objects?
How can I find how many objects are currently colliding with a certain Gameobject?
For example, I have a box and inside the box there are 2 more boxes, so It should return me that there are currently 2 objects inside the box.
Thanks in advance.
Answer by $$anonymous$$ · Aug 17, 2013 at 03:15 PM
Use: http://docs.unity3d.com/Documentation/ScriptReference/Collider.OnCollisionEnter.html http://docs.unity3d.com/Documentation/ScriptReference/Collider.OnCollisionStay.html;
int ammountOfObjectsCollided;
void OnCollisionEnter(Collision coll)
{
ammountOfObjectsCollided++;
}
When something collides with this object, variable ammountOfObjectsCollided increases. Or you can change variable form another script. For example: First script has variable public float ammount; Second script is accesing this variable;
void OnCollisionStay(Collision coll)
{
coll.gameobject.GetCommponet<FirstScript>().ammount++;
}
Your answer
Follow this Question
Related Questions
Cubes wont Collide 1 Answer
Disabling objects from Collision detection 1 Answer
Colliders not working with Character VS House 0 Answers
Collision details 1 Answer