- Home /
unity how to make objects look at random objects with the same tag
for a group project we are creating a space ship game and i am trying to figure out how to make the enemy tagged objects look at random objects with the same tag. so far the enemy tagged objects and the player tagged objects fly towards one ship at a time but i want them all to fly at random different objects.
please help its my first time creating AI
update: Can two AI's pick the same tagged object? yes but too many are picking the same object
When/where does the AI pick a new target? after the ai is destroyed (in this game more will spawn but i havent programmed the prefab)
Is rotation on all axes or only on the 'Y' axis? y and x axis,
What language? C#
Can two AI's pick the same tagged object? yes but too many are picking the same object
When/where does the AI pick a new target? after the ai is destroyed (in this game more will spawn but i havent programmed the prefab)
Is rotation on all axes or only on the 'Y' axis? y and x axis,
What language? C#
Answer by robertbu · Nov 03, 2014 at 05:39 AM
private Transform target;
void Start() {
GameObject[] gos = GameObject.FindGameObjectsWithTag("SomeTag");
target = gos[Random.Range(0, gos.Length);
}
void Update() {
transform.LookAt(target);
}