title: Respawn AI after destroy
body: <p>I'm new, and I've got hard time to respawn my AI (right now he just a cube that follow my player) after he been destroy. I believe its because the script sits on the object that get destroyed. but what I need to do to respawn it?</p>
  <p>(although I'm sure my respawn code is not good :\ (It's mobile-android project) )</p>
  <pre><code>using System;
  using System.Collections;
  using System.Collections.Generic;
  using UnityEngine;
  
  public class EnemyTesting : MonoBehaviour
  {
  
      [SerializeField]
      public GameObject player;
      public GameObject enemy;
      private Rigidbody body;
  
      Vector3 accelerationDir;
  
      // Use this for initialization
      void Start()
      {
          body = GetComponent&lt;Rigidbody&gt;();
      }
      private void Update()
      {
          accelerationDir = Input.acceleration;
  
          if (accelerationDir.sqrMagnitude&gt;=5)
          {
              EnemyDead();
          }
      }
  
      void EnemyDead()
      {
  
          Destroy(enemy);
          Invoke(&quot;Respawn&quot;, 5);
      }
      void Respawn()
      {
          enemy = (GameObject)Instantiate(enemy);
          enemy.transform.position = transform.position;
      }
     
  
      // Update is called once per frame
      void FixedUpdate()
      {
          Vector3 toTarget = player.transform.position - transform.position;
          float speed = 1.5f;
  
          transform.Translate(toTarget * speed * Time.deltaTime);
      }
  }
  </code></pre>
  <p>Thanks very much!</p>