Spawn on trigger, and follow Target
I am looking to spawn an object (tour guide robot) that will spawn when the player (target) enters a facility through a door. I am using an animator on the door for it to open using OnTriggerEnter. This robot will spawn when the user enters the trigger zone of the door.
I have attached the script to open the door and spawn the robot to the door. The object spawned is not in in the scene until it is spawned, therefore, I am unable to attach the script to that object. When incorporating the instructions to follow the target to the same script as the one that opens the door, the door ends up following the player around instead of the spawned object.
Please help. Here is the script I am using:
public class guideTrigger : MonoBehaviour {
 public GameObject spawnee;
 public float spawnTime= 5.0f;
 public Transform spawnPos ;
 private int spawnCount;
 // Get Spawnee to follow player
 //private Vector3 offset;
 public Transform target;
 public Transform myTransform;
 void Start()  {
     spawnCount = 0;
      }
 void OnTriggerEnter(Collider other) {
     if (other.gameObject.tag == "Player"/*other.gameObject.CompareTag("Player")*/)    {
        InvokeRepeating("spawnObject", 0.5f, spawnTime);
        spawnCount = spawnCount + 1;
     }
     if (spawnCount > 1)  {
       Destroy(this.gameObject);
     }
     //offset = other.transform.position - spawnee.transform.position;
    }
 void spawnObject()    {
         Instantiate(spawnee, spawnPos.position, spawnPos.rotation);
 }
 private void LateUpdate()    {
     spawnee.transform.LookAt(target);
     spawnee.transform.Translate(Vector3.forward * 5 * Time.deltaTime);
 }
 //private void LateUpdate() {
 //    spawnPos.position = spawnee.transform.position + offset;
 //}
 
               }
Your answer
 
             Follow this Question
Related Questions
how to make the random enemy generation with in the orthographic view of camera? 0 Answers
How i make the AI follow player by tag 1 Answer
Checkpoint and Respawn 0 Answers
C# access a generic list from another controller -1 Answers
Spawning with trigger 2 Answers