- Home /
Playing a different sprite prefab on collission.
Hello,
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)
{
StartCoroutine(waitFunction());
audio.loop = false;
audio.clip = _crash;
audio.Play();
Destroy(this.gameObject,_crash.length);
//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?
Thanks.
Comment
Answer by CScherer549 · Jul 20, 2014 at 07:27 PM
Do you mean instantiate one and have it play an animation? The Unity Script Reference would be the first place to look for that. http://docs.unity3d.com/ScriptReference/
Your answer
Follow this Question
Related Questions
Destroying object when player walks over it 1 Answer
Emit Particle on Collision Issue 0 Answers
Moving assets from one project to the next 1 Answer
Destroying a prefab with a prefab? 2 Answers