码迷,mamicode.com
首页 > 其他好文 > 详细

用技能对敌人造成伤害的方法

时间:2016-04-19 11:59:16      阅读:112      评论:0      收藏:0      [点我收藏+]

标签:

 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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!