- Home /
 
Get attacked by enemies when they spawn
hello! so i have this script to make the enemies spawn with a delay.. and what i need is that every time an enemy spawns, it attacks the player with a projectile.
 public class TimedSpawn : MonoBehaviour {
 
     public GameObject spawnee;
     public bool stopSpawning;
     public float spawnTime;
     public float spawnDelay;
 
     // Use this for initialization
     void Start () {
         InvokeRepeating ("SpawnObject", spawnTime, spawnDelay);
     }
 
     public void SpawnObject (){
         Instantiate (spawnee, transform.position, transform.rotation);
 
         if (stopSpawning) {
             CancelInvoke ("SpawnObject");
         }
     }
 }
 
              Answer by Cuttlas-U · Oct 25, 2017 at 06:44 AM
hi; well when u instantiate them first thing they need is to find the player Transform; so u can do it with :
  GameObject.Find
 
               or any other way !
then the player need to face that transform like :
 transform.LookAt(player);
 
               or any way u do it;
then u need to shoot the bullut or object for this u need to Instantiate it with this code:
 Instantiate ( bullutObject);
 
 
               your bullut should have a code attached to it to move forward and get to the player;
 transform.Translate(Vector3.forward * MoveSpeed * Time.deltaTime);
 
               these are some example steps i told u ;
u need to work on each step and make it ;
ask me any question u have;
good luck ;
Your answer
 
             Follow this Question
Related Questions
Creating basic enemy animation and attacking 4 Answers
Multiple Enemy Collision Help 0 Answers
How to make an enemy attack every few seconds 1 Answer
Enemy AI problems 2 Answers
Problem with enemy AI 1 Answer