- Home /
How do i apply some AISeeking code to all instances of a sprite, it is contained with the ship it is seeking but only 1 follows it
Basically i have some code which makes my enemy ship follow my hero ship, however when i spawn multiple instances of the sprite only the first one has the script applied to it, the clone is tagged and everything seems to be correct. The code is found below.
seekingAI.gameObject.SendMessage("SeekPlayer", shipLoc); This is the code that on every update tells the enemy to seek the hero ship with my coordinates. SeekingAI is the enemy which i drop into the variables from the hierarchy.seekingAI = GameObject.FindGameObjectWithTag("Enemy").transform;
Instantiate(enemy, new Vector3(x, y, 0), Quaternion.identity);
This is the code that spawns my enemy, x and y are changeable at the moment for testing. enemy is set to a Transform which is drag and dropped as the enemy in the hierarchy later.
I've paused the scene after pressing play and all the clones have the tag enemy. Should i be using the prefabs instead of objects from hierarchy? If so, how? because when i drag and drop from the prefabs the hero adopts the enemies collision box and act wierd.
Your answer
Follow this Question
Related Questions
Assign an instantiated GameObject? 1 Answer
Can't remove instantiated prefab 0 Answers
How do i Clone a gameObject when pressing "F"? 2 Answers
Deleting a GameObject 2 Answers
parenting instantiated object 2 Answers