Help using tags?

I am creating an RTS game with two types of units: ground and ar. I want ground units to only attack ground units and air units to only attack air units, with a few exceptions. To do this, I’ve given all the ground units the tag “ground” and all air units the tag “air”. I’d like to have the main camera constantly broadcast what it’s looking at to every single gameObject, weather the mouse is pointing at the terrain, an air unit, or a ground unit. How can I get the camera to do this, or is there a better way to do what I’m trying to do?

so, first, you want a piece of code that says something like this: (note that we are asking the camera what it’s target is rather then broadcasting it)

var target=GameObject.Find("Main Camera").GetComponent("CameraScript").target;
if(target)if(target.tag=="ground")AttackUnit(target);

You will need to make an AttackUnit() function in the script to start the attack. Also, you may wish to have a rounds per second counter so you are not continuously spitting rounds every 0.02 seconds.

And so for the Air units…

var target=GameObject.Find("Main Camera").GetComponent("CameraScript").target;
if(target)if(target.tag=="air")AttackUnit(target);

The camera is a little more iffy, though I am confused a little. I assume that you want the camera’s target, but camera’s don’t start out with targets. So lets make one:

var target : Transform;
function Update(){
this.transform.LookAt(target.position);
}

You will need to tack in some code to “select an object” and fill target on the fly. You can do this by mouse click or just general vicinity. All of that can be found someplace in the forums here though.

Hmm… would that code be in the script I have for each unit? I assume yes. I just want to know what the tag is of the unit that the mouse is over… should be easy enough with a raycast, I can set that as the camera’s target maybe. Thanks for the help.