Playing a different sprite prefab on collission.


I have a sprite animation for a flying UFO and another sprite animation for an explosion. Right now I have the following script attached to the flying UFO sprite prefab:

using UnityEngine;
using System.Collections;

public class GroundCollide : MonoBehaviour {

	public AudioClip _crash;

	// Use this for initialization
	void Start () {
	// Update is called once per frame
	void Update () {

	void OnCollisionEnter2D(Collision2D collision) 
		audio.loop = false;
		audio.clip = _crash;
		//print( "BOOM" );

	IEnumerator waitFunction()
		float timeToWait = 5;
		yield return new WaitForSeconds(timeToWait); 

My question is, how do I get the explosion sprite prefab to play inside the OnCollisionEnter2D before my main UFO sprite prefab is destroyed?


Do you mean instantiate one and have it play an animation? The Unity Script Reference would be the first place to look for that.