游戏开发学习笔记(十五)怪物系统
来源:互联网 发布:js遍历jsonarray对象 编辑:程序博客网 时间:2024/05/22 16:07
//思路:
//判断距离,在设定距离内,走向主角
//在攻击距离内,攻击主角
//受到伤害处理
新建脚本Enemy,编辑脚本,在属性面板分别赋值敌人的属性(类型,血量,攻击,防御,速度等)
public enum EnemyType{ Boos, Leader, Monster, UltimateBoss}public class Enemy : MonoBehaviour { public static Enemy _instance; public EnemyType enemyType = EnemyType.Monster; public float hp = 100; public float attack = 10; public float def = 5; public float speed = 3; private Animator anim; private CharacterController CC; private GameObject player; private float timer = 0; //计时器,攻击计时 private float time = 2; private bool ismoved = false;void Awake () { _instance = this; } void Start() { player = TransformScripManage._instance.Player; if (enemyType != EnemyType.UltimateBoss) { anim = this.GetComponent<Animator>(); CC = GetComponent<CharacterController>(); } } void Update() { if (player != null && PlayerState._instance.ReadremainHp() > 0) { ClosePlayer(); } } //走向主角 void ClosePlayer() { float distance = Vector3.Distance(transform.position, player.transform.position); //判断距离 if (distance <= 10) { ismoved = true; if (distance >= 2.5) //判断是否在攻击距离内 { if (enemyType != EnemyType.UltimateBoss) //非终极Boss { anim.SetInteger("Idle_Run", 3); if (anim.GetCurrentAnimatorStateInfo(1).IsName("Empty State")) //当状态机处于“Empty State”时,及非攻击状态时。 { transform.LookAt(player.transform); CC.SimpleMove(transform.forward * speed); } } } else { anim.SetInteger("Idle_Run", 1); Attack(); } } else { if (ismoved) { ismoved = false; anim.SetInteger("Idle_Run", 1); } } } //攻击主角 void Attack() { if (player != null && PlayerState._instance.ReadremainHp() > 0) //当主角非死亡时 { timer += Time.deltaTime; if (timer > time) //计时器 { anim.SetTrigger("Attack"); if (hp > 0) PlayerState._instance.Hurt(attack); transform.LookAt(player.transform); timer = 0; } } } //受到伤害 void Hurt(float amountHurt) { if (hp > 0) { anim.SetTrigger("Damage"); amountHurt -= (Random.Range(1, 5) + def); hp -= amountHurt; } if (hp <= 0) { anim.SetTrigger("Dead"); TransformScripManage._instance.Destory(this.gameObject); } }}
阅读全文
0 0
- 游戏开发学习笔记(十五)怪物系统
- 跟着BOY学习开发cocos2d-x 游戏 实战篇(4)之 游戏主界面 -----怪物系统---赌徒来袭
- 跟着BOY学习开发cocos2d-x 游戏 实战篇(4)之 游戏主界面 -----怪物系统---赌徒来袭
- 开发cocos2d-x 游戏 实战篇(4)之 怪物系统
- Android开发笔记学习秘籍(十五)
- 游戏开发学习笔记(七)开发背包系统
- Cocos2d-x怪物智能AI怪物也有智商----之游戏开发《赵云要格斗》(6)
- 【D3D11游戏编程】学习笔记十五:混合(Blending)
- MFC学习笔记之三(粒子系统+怪物简单AI+碰撞检测)
- cocos2dx游戏开发学习笔记(六)之坐标系统
- 游戏开发学习笔记(九)商店系统
- 【Visual C++】游戏开发笔记十五 游戏人工智能(一) 运动型游戏AI
- 【Visual C++】游戏开发笔记十五 游戏人工智能(一) 运动型游戏AI
- 【Visual C++】游戏开发笔记十五 游戏人工智能(一) 运动型游戏AI .
- 游戏开发笔记十五 游戏人工智能(一) 运动型游戏AI
- 【Visual C++】游戏开发笔记十五 游戏人工智能(一) 运动型游戏AI
- 【Visual C++】游戏开发笔记十五 游戏人工智能(一) 运动型游戏AI
- 学习笔记(十五)
- Keras 入门课1 -- 用MLP识别mnist手写字符
- 测试格式
- 深度学习: translation invariant (平移不变性)
- ES6学习13章:Promise对象
- lwp和线程区别
- 游戏开发学习笔记(十五)怪物系统
- 双调排序进阶:对任意长度的序列排序
- 微信小程序----App生命周期
- bash shell的配置
- 2017.12.18 第七、八天-java接口对接
- 【知识整理】Axios-如何发送一个GET请求
- git Download github 项目
- Spacevim
- 面向对象的理解