临时1

  1 using UnityEngine;
  2 using System.Collections;
  3
  4 public enum WolfState
  5 {
  6     Idle,
  7     Walk,
  8     Attack,
  9     Death
 10 }
 11
 12 public class WolfBaby : MonoBehaviour {
 13     public WolfState state = WolfState.Idle;
 14     public string aniname_death;
 15     //public string aniname_now;
 16     public string aniname_walk;
 17     public string aniname_idle;
 18     public float time = 1;
 19     public float speed=1;
 20     public int hp = 100;
 21     public int attack = 10;
 22     public GameObject body;
 23     public AudioClip miss_sound;
 24
 25     private int exp = 20;//杀死一只小狼获得的经验值
 26     private float timer = 0;
 27     public string aniname_now;//当前的状态
 28     private CharacterController cc;
 29     public float missRate = 0.2f;
 30     public PlayerStates ps;
 31     private Color normal;
 32
 33     private GameObject hudtextFollow;
 34     private GameObject hudtextGo;
 35     public GameObject hudtextPrefab;
 36     private HUDText hudtext;
 37     private UIFollowTarget followTarget;
 38
 39     public string aniname_normalattack;//普通攻击
 40     public float time_normalattack;//普通攻击计时器
 41
 42     public string aniname_crazyattack;//疯狂攻击
 43     public float time_crazyattack;//疯狂攻击计时器
 44     public float crazyattack_rate;//疯狂攻击的几率
 45
 46     public string aniname_attack_now;//当前的攻击
 47     public int attack_rate = 1;//攻击速率 每秒
 48     private float attack_timer = 0;
 49
 50
 51     private Transform target;//攻击的目标
 52     public float minDistance = 2;//攻击的最小距离
 53     public float maxDistance = 5;//攻击的最大距离
 54
 55     public WolfSpawn spawn;
 56
 57
 58     void Awake() {
 59         ps = GameObject.FindGameObjectWithTag(Tags.player).GetComponent<PlayerStates>();
 60         aniname_now = aniname_idle;
 61         cc = transform.GetComponent<CharacterController>();
 62         normal = body.renderer.material.color;
 63         hudtextFollow = transform.Find("HUDText").gameObject;
 64     }
 65
 66     void Start() {
 67         //hudtextGo = GameObject.Instantiate(hudtextPrefab, transform.position, Quaternion.identity) as GameObject;
 68         hudtextGo = NGUITools.AddChild(HUDTextParent._instance.gameObject, hudtextPrefab);
 69         //hudtextGo.transform.parent = HUDTextParent._instance.gameObject.transform;
 70         hudtext = hudtextGo.GetComponent<HUDText>();
 71         followTarget = hudtextGo.GetComponent<UIFollowTarget>();
 72         //print(hudtextFollow.transform);
 73         followTarget.target = hudtextFollow.transform;
 74         //print(followTarget.target);
 75         followTarget.gameCamera = Camera.main;
 76         //followTarget.uiCamera = UICamera.current.GetComponent<Camera>();
 77     }
 78
 79     void Update() {
 80         if (state == WolfState.Death) {
 81             animation.CrossFade(aniname_death);
 82         }
 83         else if (state == WolfState.Attack) {
 84             AutoAttack();
 85         }
 86         else{ //巡逻
 87             animation.CrossFade(aniname_now);
 88             if (aniname_now == aniname_walk) {
 89                 cc.SimpleMove(transform.forward * speed);
 90             }
 91             timer += Time.deltaTime;
 92             if (timer > time) {
 93                 RandomState();
 94                 timer = 0;
 95             }
 96
 97         }
 98
 99         if (Input.GetMouseButtonDown(0)) {
100             TakeDamage(2);
101         }
102
103     }
104
105     //随机转换Idle和Walk的状态
106     void RandomState() {
107         int value = Random.Range(0, 2);
108         if (value == 0)
109         {
110             aniname_now = aniname_idle;
111         }
112         else {
113             if(aniname_now!=aniname_walk){
114                 cc.transform.Rotate(transform.up * Random.Range(0, 360));
115             }
116             aniname_now = aniname_walk;
117         }
118
119     }
120
121     //伤害效果
122     public void TakeDamage(int attack ) {
123         if (state == WolfState.Death)
124             return;
125
126         //如果小狼受到伤害的话,让小狼攻击主角
127         target = GameObject.FindGameObjectWithTag(Tags.player).transform;
128         state = WolfState.Attack;
129
130         float value = Random.Range(0f, 1f);
131         if (value < missRate)
132         { //miss效果
133             AudioSource.PlayClipAtPoint(miss_sound, transform.position);
134             hudtext.Add("Miss", Color.gray, 1);
135         }
136         else {//击中效果
137             hudtext.Add("--" + attack, Color.red, 1);
138             this.hp -= attack;
139             StartCoroutine(ShowBodyRed());
140             if (hp < 0) {
141                 state = WolfState.Death;
142                 Destroy(this.gameObject, 2);
143             }
144         }
145     }
146
147     IEnumerator ShowBodyRed() {
148         body.renderer.material.color = Color.red;
149         yield return new WaitForSeconds(1f);
150         body.renderer.material.color = normal;
151     }
152
153     void AutoAttack() {
154         if (target != null)
155         {
156             float distance = Vector3.Distance(target.position, transform.position);
157             if (distance > maxDistance)
158             {
159                 target = null;
160                 state = WolfState.Idle;
161             }
162             else if (distance <= minDistance)//攻击
163             {
164                 attack_timer += Time.deltaTime;
165                 animation .CrossFade (aniname_attack_now);
166                 if (aniname_attack_now == aniname_normalattack) {
167                     if (attack_timer > time_normalattack) {
168                         //伤害TODO
169                         aniname_attack_now = aniname_idle;
170                     }
171                 }
172                 else if (aniname_attack_now == aniname_crazyattack) {
173                     if (attack_timer > time_crazyattack) {
174                     //产生伤害TODO
175                         aniname_attack_now = aniname_idle;
176                     }
177                 }
178                 //连续攻击
179                 if (attack_timer > 1 / attack_rate) {
180                     RandomAttack();
181                     attack_timer = 0;
182                 }
183
184             }
185             else
186             { //朝着角色行走
187                 transform.LookAt(target.transform);
188                 cc.SimpleMove(transform.forward * speed);
189                 animation.CrossFade(aniname_walk);
190             }
191         }
192         else {
193             state = WolfState.Idle;//进行巡逻
194         }
195     }
196
197     //当MonoBehaviour将被销毁时,这个函数被调用
198     //此处就是当wolfbaby被销毁时,调用该函数
199     void OnDestory() {
200         spawn.minusNumber();
201         ps.GetExp(exp);
202         BarNPC._instance.OnKillWolf();
203         Destroy(hudtextGo);
204     }
205
206     //随机攻击状态
207     void RandomAttack() {
208         float value = Random.Range(0, 1);
209         if (value < crazyattack_rate)
210         {
211             aniname_attack_now = aniname_crazyattack;
212         }
213         else {
214             aniname_attack_now = aniname_normalattack;
215         }
216     }
217
218     //当鼠标放上时,修改鼠标显示样式
219     void OnMouseEnter() {
220         CursorManager._instance.SetAttack();
221     }
222 }
时间: 2024-08-03 01:25:23

临时1的相关文章

Java企业微信开发_09_素材管理之下载微信临时素材到本地服务器

一.本节要点 1.获取临时素材接口 请求方式:GET(HTTPS) 请求地址:https://qyapi.weixin.qq.com/cgi-bin/media/get?access_token=ACCESS_TOKEN&media_id=MEDIA_ID 2.获取临时素材接口的返回结果 企业微信官方开发文档中说明的返回结果如下: 若你以为这就是返回结果,然后跟之前一样,先访问接口,从http连接的输入流中的获取回结果的文本内容,你会发现你接收到的结果是一堆乱码. 这是为何? 以图片为例,此处千

Nginx学习笔记15rewrite之(二)redirect临时重定向

redirect标志跟permanent标志的区别是:redirect使用HTTP 302临时重定向,permanent使用HTTP 301永久重定向.本文介绍redirect标志的临时重定向动作. Nginx配置: location ~ ^/app2/ { rewrite ^/app2/(.*)$  /app/$1  redirect; } 运行结果: curl -v   http://ng.coe2coe.me:8000/app2/ * Hostname was NOT found in D

arm-linux内存管理学习笔记(2)-内核临时页表的建立

学习了arm内存页表的工作原理,接下来就开始咱们软件工程师的本职工作,对内核相关代码进行分析.内核代码那么复杂,该从哪里下手呢,想来想去.其实不管代码逻辑如何复杂,最终的落脚点都是在对页表项的操作上,那么内核是在什么时机会对页表项进行操作,如何操作? 对于一个页表项,抛开所有的软件复杂逻辑,操作无非就是2种吧.一是填写更新页表项,二是读取获取页表项. MMU负责根据页表项进行虚实地址转换,因此读取获取页表项的工作是MMU硬件完成,软件是不参与的.内核代码的主体工作是来更新内存页表.页表更新的时机

如何处理服务器SSL收到了一个弱临时Diffie-Hellman 密钥?

处理服务器SSL收到了一个弱临时Diffie-Hellman 密钥 当我们用火狐浏览器打开某个HTTPS网站时可能会失败,并且出现如下错误提示:         安全连接失败连接某个URL网址时发生错误. 在服务器密钥交换握手信息中 SSL 收到了一个弱临时 Diffie-Hellman 密钥.         错误码: ssl_error_weak_server_ephemeral_dh_key) 如果换用谷歌Chrome打开这个相同的网页也会发生错误,并提示:            服务器的

webform之session传值(临时数据的存储)与扩展属性 --(购物车练习)

页面传值:1.QueryString传值在源页面写:Response.Redirect("Main.aspx?uid="+uid+"&pwd="+pwd);在目标页面:Request["uid"].ToString();2.Session *****特点:可以存任何东西,每个用户都会生成一个特定的Session,Session是存储在服务中的,一般默认存储20分钟,20分钟之后过期用法:在登录页面:Session["uid&qu

域名无法解析 Linux临时或永久修改DNS

最近给VPS重装了系统,因为服务商不提供DHCP,所以只好手动设置IP和DNS Server.悲催的是系统重装的时候忘记了输入DNS Server,最后导致进去系统后,各种域名无法解析. Linux中修改DNS有两种方式,临时修改和永久修改,下面分别介绍. 1.临时修改网卡DNS地址 sudo vim /etc/resolv.conf 改为如下内容: nameserver 8.8.8.8 #修改成你的主DNS nameserver 8.8.4.4 #修改成你的备用DNS search local

代码重构之以查询取代临时变量

意图 - 使得同一个类中的所有函数都可以获得这份信息,能够为这个类编写更清晰的代码 示例 /** * 以查询取代临时变量之前 * Created by luo on 2017/4/19. */ public class ReplaceTempWithQueryBefore { private double _quantity; private double _itemPrice; public double test() { double basePrice = _quantity * _ite

临时任务总结

今天接到临时任务,要求把一个死数据改成从数据库获取,这个过程,略慌乱,导致浪费了时间,以后有紧急事务,要先分析到最好,最快的方法,不要乱试,浪费时间,学习坦克大战时的精神,以及坦克大战中高手的武艺 另外 ,个人的修行,才会导致做事的改变,要想改变做事,先改变自己,要精准,不能有一丝差错,一个字母 错,整个程序完蛋,切记. 要慢,慢才能快,静才能快,静才能想到好办法,急匆匆,如傻叉,不断更新自己,不断改变

简单即用的临时Map容器(参考TimeCacheMap和RotatingMap)

因为业务需要,经常会缓存一些临时数据.比如:手机号发送验证码, 60s内同一个手机号不能重复发送验证码.查询航班信息,缓存1分钟热门查询数据.... 之前一直使用redis作为数据缓存,简单方便..但是如果是个小App,数据没有那么大,可能需要缓存的数据只有不到100KB,使用redis就大材小用 最近一个项目上线的时候,老大跟我说:真的有必要用redis么..不行就先删掉吧..自己想了下,因为App入口有两个ip,不同机器,虽然业务量不大,为了session共享,还是上了 如果只有一个入口(不

linux基础篇-24,swap交换分区临时救急及划分方法

################################################ swap 查看物理内存和交换分区大小及其使用情况 [[email protected] ~]# free -m total       used       free     shared    buffers     cached Mem:          1869        192       1676          0         13         65 -/+ buffer