- Home /
How to make multiple targets?
How can I make multiple targets for one attacker? Since I want to design a attacker within a game, I want to set multiple targets for the attacker. These targets are with different tags. How can I do this?
Please be more specific. How do you want to "detect" the targets and since a "normal" attacker can only attack one target at a time how do you want to handle priority? distance? Or is your attacker able to attack multiple targets at the same time?
oh and please if you want code samples tell us what language you want to use? C# or Javascript?
Answer by Borgo · Feb 01, 2011 at 01:08 PM
The best way to do this is to use the tags, but, if your targets have different tags, I can't see another way than this:
- Make a gameobject that will be your "targets control";
- Make in this control a array that will store your targets transforms;
- Make your targets to be "registered" in this control when created;
- Make your targets to be "unregistered" in this control when destroyed;
A little and simple example:
To control;
var targets = new Array();
function registerTarget(tr : Transform){
targets.Push(tr);
}
To targets:
function Start(){
var targetsControl = GameObject.Find("/TargetsControl");
targetsControl.GetComponent(TargetControlScript).registerTarget(transform);
}