I have some code in a primarily 2d game for moving a UFO and creating an explosion when the UFO gets hit by a missile:
using UnityEngine;
using System.Collections;
public class UFOmover : MonoBehaviour {
public GameObject particleExplosion;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
this.transform.Translate (0.01f, 0, 0);
}
void OnTriggerEnter2D(Collider2D other)
{
Instantiate (particleExplosion, this.transform.position, Quaternion.identity);
Debug.Log ("trigger triggered");
Destroy (this.gameObject);
}
}
However, the problem is the explosion seems to always show up behind the background. Any ideas how to fix this?
I tried changing the Z value of the explosion and putting it on the top layer, but the explosion still seemed to be behind the background.