protected virtual void Shot(FBMonster monster) { if (f_animator.gameObject.activeSelf) { f_animator.SetTrigger("IsAttack"); } }
private void MonSterReched(FBMonster monster) { //萝卜掉血 f_carrot.Damage(1); //怪物死亡 monster.HP = 0; }
public void Load(int bulletID, int level, Rect mapRect, FBMonster monster) { Load(bulletID, level, mapRect); Target = monster; //计算方向 Direction = (Target.transform.position - transform.position).normalized; }
private void OnSpawnMonster(FBSpawnMonsterArgs args) { //创建怪物 string monsterName = "Monster" + args.MonsterID; GameObject go = FBGame.Instance.ObjectPool.Spawn(monsterName); FBMonster monster = go.GetComponent <FBMonster>(); monster.HPChangedAction += MonsterHPChanged; monster.DeadAction += MonsterDead; monster.ReachedAction += MonSterReched; monster.OnLoad(f_map.Path); }
protected override void Shot(FBMonster monster) { base.Shot(monster); for (int i = 0; i < f_bulletCount; i++) { float radians = (Mathf.PI * 2f / f_bulletCount) * i; Vector3 dir = new Vector3(Mathf.Cos(radians), Mathf.Sin(radians), 0f); //产生子弹 GameObject go = FBGame.Instance.ObjectPool.Spawn("FanBullet"); FBFanBullet bullet = go.GetComponent <FBFanBullet>(); bullet.transform.position = transform.position;//中心点 bullet.Load(this.UseBulletID, this.Level, this.MapRect, dir); } }
protected override void Shot(FBMonster monster) { base.Shot(monster); if (f_animator.gameObject.activeSelf) { f_animator.SetTrigger("IsAttack"); } GameObject go = FBGame.Instance.ObjectPool.Spawn("BallBullet"); FBBallBullet bullet = go.GetComponent <FBBallBullet>(); bullet.transform.position = f_shotPoint.position; bullet.Load(UseBulletID, Level, MapRect, monster); }
private void LookAt(FBMonster target) { if (target != null) { Vector3 dir = (f_target.transform.position - transform.position).normalized; float angle = Mathf.Atan2(dir.y, dir.x) * Mathf.Rad2Deg; Vector3 eulerAnglles = transform.eulerAngles; eulerAnglles.z = angle - 90f; transform.eulerAngles = eulerAnglles; } else { Vector3 eulerAnglles = transform.eulerAngles; eulerAnglles.z = 0; transform.eulerAngles = eulerAnglles; } }
protected override void Update() { //已爆炸跳过 if (f_isExploded) { return; } //移动 transform.Translate(Direction * Speed * Time.deltaTime, Space.World); //旋转 transform.Rotate(Vector3.forward, RotateSpeed * Time.deltaTime, Space.World); //检测(存活/死亡) GameObject[] monsterObjects = GameObject.FindGameObjectsWithTag("Monster"); foreach (GameObject monsterObject in monsterObjects) { FBMonster monster = monsterObject.GetComponent <FBMonster>(); //忽略已死亡的怪物 if (monster.IsDead) { continue; } if (Vector3.Distance(transform.position, monster.transform.position) <= FBConsts.RangeClosedDistance) { //敌人受伤 monster.Damage(this.Attack); //爆炸 Explode(); //退出(重点) break; } } //边间检测 if (!f_isExploded && !MapRect.Contains(transform.position)) { Explode(); } }
public override void OnUnspawn() { if (f_animator.gameObject.activeSelf) { f_animator.ResetTrigger("IsAttack"); } f_animator = null; f_target = null; ID = 0; Level = 0; MaxLevel = 0; BasePrice = 0; GuardRange = 0; ShotRate = 0; UseBulletID = 0; f_grid = null; }
void Update() { //转向目标 if (f_target == null) { GameObject[] monsters = GameObject.FindGameObjectsWithTag("Monster"); foreach (GameObject m in monsters) { FBMonster monster = m.GetComponent <FBMonster>(); float dis = Vector3.Distance(transform.position, monster.transform.position); if (!monster.IsDead && dis <= GuardRange) { f_target = monster; break; } } LookAt(f_target); } else { float dis = Vector3.Distance(transform.position, f_target.transform.position); if (f_target.IsDead && dis > GuardRange) { f_target = null; LookAt(f_target); } else { LookAt(f_target); float attackTime = f_lastShotTime + 1f / ShotRate; if (Time.time >= attackTime) { Shot(f_target); f_lastShotTime = Time.time; } } } }