title: Unity 2D - How to play death animation prefab
body: <p>I have created a prefab with animation from sprite sheet, which I want to be played when the Player dies. I checked if the prefab is working by dragging it in the Scene, and it is correctly playing every frame of the sprite sheet in a loop endlessly.</p>
  
  <p>Now I want to play this prefab when the Player dies, and after it ends to destroy it, but so far I am only able to place it where the player dies, and it stays there forever. Also there are some errors when that happens.</p>
  
  <p>Here is the death script:</p>
  
  <pre><code> public class DmgByCollisionEnemy : MonoBehaviour {
  
      public GameObject deathAnimation;
  
      void Die() {
          deathAnimation = (GameObject) Instantiate(deathAnimation, transform.position, transform.rotation);
          //Destroy(deathAnimation);
          Destroy(gameObject);
      }
  }
  </code></pre>
  
  <p>I set the deathAnimation by dragging a prefab in the Unity interface.</p>
  
  <p>The error I am getting when the <code>Die()</code> method fires is</p>
  
  <pre><code>UnassignedReferenceException: The variable deathAnimation of DmgByCollisionEnemy has not been assigned.
  You probably need to assign the deathAnimation variable of the DmgByCollisionEnemy script in the inspector.
  </code></pre>
  
  <p>So how can I do that properly?</p>