using UnityEngine; using System.Collections; public class Life : MonoBehaviour { public int life = 1; public int resistance = 0; private AudioSource source; public AudioClip Constant_sounds; public AudioClip On_Destroy_noise; public AudioClip On_Contact_sounds; public AudioClip On_Hit_sounds; public GameObject start_effect; public GameObject end_effect; public GameObject[] On_Die_Spawn; public GameObject[] On_Damaged_Spawn; void Start(){ if(start_effect!=null){ GameObject effect = Instantiate(start_effect,transform.position,transform.rotation) as GameObject; effect.AddComponent(); effect.GetComponent().tme=2; } source = GetComponent(); if(Constant_sounds!=null){ source.PlayOneShot(Constant_sounds,PlayerPrefs.GetFloat("VOLUME", 0.5f)); source.loop = true; } } void Update(){ if(life<=0){ if(On_Destroy_noise!=null){source.PlayOneShot(On_Destroy_noise,PlayerPrefs.GetFloat("VOLUME", 0.5f));} if(end_effect!=null){ GameObject effect = Instantiate(end_effect,transform.position,transform.rotation) as GameObject; effect.AddComponent(); effect.GetComponent().tme=2; } if(On_Die_Spawn.Length>0 && On_Die_Spawn!=null){ Instantiate(On_Die_Spawn[Random.Range(0,On_Die_Spawn.Length-1)], transform.position, transform.rotation); } Destroy(gameObject); } } public void Be_Hitten(int damage){ if(damage-resistance>0){ life-=damage-resistance; if(On_Hit_sounds){ source.PlayOneShot(On_Hit_sounds,PlayerPrefs.GetFloat("VOLUME", 0.5f)); } } } public void Be_Hitten(int damage, ContactPoint contactP){ if(damage-resistance>0){ life-=damage-resistance; ////ON HIT NOISE if(On_Hit_sounds){ source.PlayOneShot(On_Hit_sounds,PlayerPrefs.GetFloat("VOLUME", 0.5f)); } ///SPAWN ON CONTACT EFFECTS if(On_Damaged_Spawn!=null && On_Damaged_Spawn.Length>0){ Quaternion Crotation = Quaternion.FromToRotation(Vector3.up, contactP.normal); Vector3 Cposition = contactP.point; Instantiate(On_Damaged_Spawn[Random.Range(0,On_Damaged_Spawn.Length)], Cposition, Crotation); } } } public void True_Damage(int damage){ if(On_Hit_sounds){ source.PlayOneShot(On_Hit_sounds,PlayerPrefs.GetFloat("VOLUME", 0.5f)); } life-=damage; } public void True_Damage(int damage, ContactPoint contactP){ if(On_Hit_sounds){ source.PlayOneShot(On_Hit_sounds,PlayerPrefs.GetFloat("VOLUME", 0.5f)); } life-=damage; ///SPAWN ON CONTACT EFFECTS if(On_Damaged_Spawn!=null && On_Damaged_Spawn.Length>0){ Quaternion Crotation = Quaternion.FromToRotation(Vector3.up, contactP.normal); Vector3 Cposition = contactP.point; Instantiate(On_Damaged_Spawn[Random.Range(0,On_Damaged_Spawn.Length)], Cposition, Crotation); } } void OnCollisionEnter (Collision col){ if(On_Contact_sounds){ source.PlayOneShot(On_Contact_sounds,PlayerPrefs.GetFloat("VOLUME", 0.5f)); } } }