Physics.IgnoreCollision with EveryGameObjectWithTag("sample")

Hey Guys,
I want this Collider only Collide with my Player so I tagged the Player as Player and applied the following Script to the Collider:
function Start ()


var cols : Collider[] = GameObject.FindGameObjectWithTag("UnCollide").GetComponents.<Collider>();

for (var C : Collider in cols)


    Physics.IgnoreCollision(C, collider);



Now I tagged all other GameObjects who collide with the Collider, with “UnCollide” so that the collider ignors them but it only ignores 1 Gameobject at the Time.
How can I make it find Every GameObject With Tag (“UnCollide”)

Thanks for your Answers =)

FindGameObjectsWithTag returns a GameObject array, and you can’t convert it directly to a Collider array - you should instead get the collider from each game object in the array, like this:

function Start (){
  var gos : GameObject[] = GameObject.FindGameObjectsWithTag("UnCollide");
  for (var go : GameObject in gos){
    Physics.IgnoreCollision(go.collider, collider);

But this is a complicated, hard working and slow way to do the job - usually it’s much easier and faster to do this with layers. It’s easy: sclick the Layer button in the Inspector and select option Add Layer…, then add two new layers: Player and Uncollide. Select the player and set its layer to Player, then select all “uncollide” objects in the Hierarchy view and set their layers to Uncollide at once. Finally, go to the Physics Manager (Edit->Project Settings->Physics) and in Layer Collision Matrix uncheck the layers you don’t want to collide with Uncollide - like this:

alt text

With these settings, objects in the Uncollide layer will only collide with objects in the layers Uncollide and Player - you won’t need to write a single line of code for this purpose!

NOTE: If any Uncollide object has a rigidbody, you must move the terrain and all objects that may serve as ground to the Player layer, or the rigibody may fall through the floor.

I think you can use GameObject.FindGameObjectsWithTag(“UnCollide”)

FindGameObjectWithTag() finds only the first object with the given tag. You have to use FindGameObjectsWithTag().

You also can try:
foreach(Collider cols in GameObject.FindGameObjectsWithTag(“UnCollide”)){

Ok Guys I fixed it and here s how I did it >It was really that simpel<:

I didnt do it by Script cuz I couldnt get it working, like I said it only finds one GameObject At the Time, so I simply created 2 new Layers. One for the Collider (LevelCollider) who should have ignored all collisions with Tag (“UnCollide”) and the other one for all Colliders who shouldnt collide with LevelCollider. Finally I put all GameObjects on the right Layer (LevelCollider on the 1st new and all the other GameObjects who collided with LevelCollider on the 2nd one)

After that, I went to my Physic Settings by hitting Edit>Project Settings>Physic and a window popped up on the inspector. Under “Layer Collision Matrix” there was a Small triangle build out of Checkboxes which detects collisions between all Layers. I unchecked the Box where my 1st New Layer and my 2nd New Layor crossed so that the Layers will not be able to collide with each other anymore =) Hit Play… Works!! :smiley:

Thanks Guys for your Help :smiley: