标签:
1 using UnityEngine; 2 using System.Collections; 3 4 public class magic : MonoBehaviour { 5 public float trock = Random.Range(10,21); 6 private float destroyTimer = 5f; 7 8 // Use this for initialization 9 10 void Start () { 11 12 StartCoroutine(destroyByTime());//开启协程程序 13 } 14 15 // Update is called once per frame 16 //第一种让魔法消失的方法 17 //void Update () { 18 // destroyTimer -= Time.deltaTime; 19 // if (destroyTimer <= 0) 20 // { 21 // GameObject.Destroy(this.gameObject); 22 // } 23 //} 24 25 public void OnTriggerStay(Collider other) { 26 if(other.tag=="Enemy") 27 { 28 29 other.GetComponent<troll>().HP -= trock * Time.deltaTime; 30 // other.GetComponent<troll>().AnimationToGet_Hit(); 31 if (other.GetComponent<troll>().HP <= 0) 32 { 33 other.GetComponent<troll>().Death(); 34 } 35 } 36 } 37 //利用协程程序进行销毁 38 IEnumerator destroyByTime() 39 { 40 yield return new WaitForSeconds(5.0f); 41 Destroy(this.gameObject); 42 } 43 44 45 }
在技能上面添加一个触发器制作成prafeb
标签:
原文地址:http://www.cnblogs.com/fuperfun/p/5407439.html