Collision Layer

How can I make a Cube with a Enemy tag on it to have a collider that can collide only certain objects.

Well heres the solution :

function Start () {
    ignoreCollision("MyTag");    
}         

function ignoreCollision(tag : String) { 
    var objects = GameObject.FindGameObjectsWithTag(tag); 
    for (o in objects) { 
        if (o.GetComponent("Collider") && o != gameObject)
        Physics.IgnoreCollision(collider, o.collider);    
    }    
} 
  • Felipe

Yes, but instead of tags you should use layers. You can set the physics layers interaction under Edit -> Project Settings -> Physics

Solution - I used a script that looks for the object with the certain tag and disables the collision.


 function Start () {    
        ignoreCollision("Respawn");    
    }       
    
    function ignoreCollision(tag : String) {    
        var objects = GameObject.FindGameObjectsWithTag(tag);     
        for (o in objects) {     
            if (o.GetComponent("Collider") && o != gameObject)    
            Physics.IgnoreCollision(collider, o.collider);     
        }     
    } 

  • Felipe