本次完成盒子僵尸的制作,其特点是该僵尸生命值低于某值的瞬间,有一定几率爆炸,将周围植物和自己炸死.
代码
盒子僵尸
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;
public class BoxZombie : ZombieBase
{
protected override int MaxHP => 570;
protected override float speed => 4;
protected override float attackValue => 100;
protected override GameObject Prefab => GameManager.Instance.GameConf.BoxZombie;
protected override bool isSpecial => false;
private bool isBoom = false;
public override Vector2 offset => new Vector2(-0.58f, -0.38f);
public override void SpecialMove()
{
return;
}
public override void InitZombieHpState()
{
zombieHpState = new ZombieHpState(
0,
new List<int>() { MaxHP,300, 90 },
new List<string>() { "BoxZombie_Walk", "BoxZombie_Walk", "BoxZombie_LostHeadWalk" },
new List<string>() { "BoxZombie-Attack", "BoxZombie-Attack", "BoxZombie_LostHeadAttack" },
new List<UnityAction>() { null,CheckBoom, CheckLostHead }
);
}
public override void OnDead()
{
if (!isSpecialDie)
{
BoxZombie_Diebody body = PoolManager.Instance.GetObj(GameManager.Instance.GameConf.BoxZombie_Diebody).GetComponent<BoxZombie_Diebody>();
body.Init(animator.transform.position);
}
}
private void CheckBoom()
{
if (Random.Range(0, 11) > 4) return;
if (!isBoom)
{
isBoom = true;
animator.Play("GoOut");
StartCoroutine(CheckBoomed());
}
}
IEnumerator CheckBoomed()
{
while (true)
{
yield return new WaitForSeconds(0.05f);
if (animator.GetCurrentAnimatorStateInfo(0).normalizedTime >= 1)
{
DoBoomHurt();
AudioManager.Instance.PlayEFAudio(GameManager.Instance.GameConf.Boom);
BoxZombieBoom boom = PoolManager.Instance.GetObj(GameManager.Instance.GameConf.BoxZombieBoom).GetComponent<BoxZombieBoom>();
boom.Init(transform.position);
BoomHurt(1800, "BoxZombie(Clone)");
}
}
}
private void DoBoomHurt()
{
Vector2 pos = new Vector2(transform.position.x, transform.position.y);
List<Grid> grids = GridManager.Instance.GetGrids(pos, 3.25f);
if (grids == null) return;
for (int i = 0; i < grids.Count; i++)
{
if (!grids[i].HavePlant)
{
continue;
}
else
{
grids[i].CurrPlantBase.Hurt(1800);
}
}
}
private void CheckLostHead()
{
if (!isLostHead)
{
isLostHead = true;
Zombie_Head head = PoolManager.Instance.GetObj(GameManager.Instance.GameConf.Zombie_Head).GetComponent<Zombie_Head>();
head.Init(animator.transform.position);
CheckState();
}
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class BoxZombie_Diebody : BaseEFObj
{
public override string AnimationName => "BoxZombie_DieBody";
public override GameObject PrefabForObjPool => GameManager.Instance.GameConf.BoxZombie_Diebody;
}
|