Question by
kamal_saleh · Apr 21, 2016 at 07:23 AM ·
c#audiosource
Only assignment, call, increment, decrement, and new object expressions can be used as a statement
using UnityEngine; using System.Collections;
public class destroy : MonoBehaviour {
public Transform killParticle; // particle to play on death
public Transform coin; // coin to spawn after death
public AudioSource[] sounds;
public AudioSource exp;
// Use this for initialization
void Start ()
{
sounds = GetComponents<AudioSource>();
exp = sounds[0];
StartCoroutine (destroyMe());
}
// Update is called once per frame
void Update ()
{
}
void OnCollisionEnter (Collision col)
{
if (col.gameObject.tag == "enemy") {
col.gameObject.GetComponent<Animation> ().CrossFade ("die"); // animation die
Instantiate (killParticle, transform.position, Quaternion.identity); // create particle
Instantiate (coin, transform.position, Quaternion.identity); // create/leave coin
exp.Play;
Destroy (col.gameObject, .1f); // destroy enemy
Destroy (this.gameObject);
}
else if (col.gameObject.tag == "Player")
{
}
else
exp.Play;
Destroy (this.gameObject);
}
IEnumerator destroyMe()
{
yield return new WaitForSeconds(5f);
Destroy (this.gameObject);
}
}
Comment
Your answer