- Home /
The question is answered, right answer was accepted
if 4 objects touched the block it will be visible or unvisible
function OnCollisionEnter (collision : Collision) {
//when the block have 4 objects touching the collision... if (collision.gameObject == 4) renderer.enabled = true;
//the block will be visible or unvisible (rendered mesh or unrendered mesh) else (collision.gameObject < 4) renderer.enabled = false; }
Answer by Owen-Reynolds · May 11, 2013 at 07:10 AM
Unity won't tell you how many different things are touching you. You have to work to count them. collision.gameObject
is the thing that just now hit you. For example, a Cube. I think you may find this difficult.
The basic idea is to declare your own integer: public var touchCount : int;
. It doesn't have to be public, but that will let you see it while you run. Then the ifs will look like if(touchCount==4)
.
But touchCount will sit there like a lump always being zero unless you change it. OnCollisionEnter might have touchCount=touchCount+1;
in it. Then, much later, subtract one in CollisionExit.