Can i make every object with a TAG casts a ray?

I have ~30 blocks on my scene.

27 are tagged as “Bad”

3 are tagged as “Good”

If 1 of the 27 “bad” fall,i want a ray that colides with a Quad and stop something.

If the 3 “good” fall and their 3 rays hits the Quad something happens.

I know how to do the if, and etc. But i dont know how to Cast a ray on every block on a same function…

Basicly i want this:

2543334--176743--upload_2016-3-7_21-29-19.png
But I want a ray on 30 different objects that are equals but in different positions.
My english is bad and I can’t explain it better :S

2543334--176745--upload_2016-3-7_21-32-55.png

More or less… thats it, every block has a ray casted, and some of them are good and some other are bad, I need to Cast a ray from every one with a function, and I have no clue about how to do it…

You can use: Unity - Scripting API: GameObject.FindGameObjectsWithTag
to find objects with a given tag.

1 Like

Thanks, now I have to study it a lot hehehe

Can you help me with that please?
I did this code:

using UnityEngine;
using System.Collections;

public class PassLevel1 : MonoBehaviour {

    GameObject[] GoodBlocks;

    void Start()
    {
        GoodBlocks = GameObject.FindGameObjectsWithTag("Good");
        foreach (GameObject good in GoodBlocks)
        {
            Transform goodPosition = good.GetComponentInChildren<Transform> ();
            //Transform goodPosition = good.GetComponent<Transform)>();
            Debug.DrawRay(transform.position, goodPosition.forward, Color.red);
        }
    }

2544039--176816--upload_2016-3-8_10-11-51.png
Here I have my CubeGood tagged as “Good” and his children, now the debug should cast a ray from the center of the cube to his child.
But it’s not working at all… :frowning: