项目实训-不死僵尸

本次加入了不死僵尸,只有被樱桃炸弹、火爆辣椒等一次性植物才能杀死,不然尸体会在短时间后复活

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;

public class UnDieZombie : ZombieBase
{

    //该僵尸死亡后尸体在短时间后复活,只有食人花或者樱桃炸弹火爆辣椒才能彻底杀死该僵尸
    protected override int MaxHP => 370;

    private bool isRevive = false;
    protected override float speed => 2;

    protected override float attackValue => 100;

    protected override GameObject Prefab => GameManager.Instance.GameConf.UnDieZombie;

    protected override bool isSpecial => false;

  //  public override Vector2 offset => new Vector2(-0.14f, -0.38f);

    public override void SpecialMove()
    {
            return;
    }

    public override void InitZombieHpState()
    {
        zombieHpState = new ZombieHpState(
           0,
           new List<int>() { MaxHP,40 },
           new List<string>() { "UnDieZombieWalk", "UnDieZombieWalk" },
           new List<string>() { "UnDieZombieAttack", "UnDieZombieAttack" },
           new List<UnityAction>() { null ,CheckRevive}
           );
    }

    public override void OnDead()
    {
        if (!isSpecialDie)  //如果不是特殊死法

        {// 创建一个死亡身体

            UnDieZombie_DieBody body = PoolManager.Instance.GetObj(GameManager.Instance.GameConf.UnDieZombie_Diebody).GetComponent<UnDieZombie_DieBody>();
            body.Init(animator.transform.position); 

        }
    }



    private void CheckRevive()
    {
        //创建一个死亡身体
        if (!isRevive)
        {
            isRevive = true;
            UnDieZombie_DieBody body = PoolManager.Instance.GetObj(GameManager.Instance.GameConf.UnDieZombie_Diebody).GetComponent<UnDieZombie_DieBody>();
            body.Init(animator.transform.position);
        }   
        State = ZombieState.Dead;

    }







}

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class UnDieZombie_DieBody : MonoBehaviour
{

    private Animator animator;
    public bool isOVer;
    private Grid currGrid;

    public void Init(Vector2 pos)
    {

        animator = GetComponent<Animator>();
        transform.position = pos;
        isOVer = false;                        //动画播放完成
        animator.speed = 1;
        currGrid = GridManager.Instance.GetGridByWorldPos(pos);   //根据当前位置获取一个网格
        animator.Play("UnDieZombieDie");

    }

    void Update()
    {
        if (!isOVer && animator.GetCurrentAnimatorStateInfo(0).normalizedTime >= 1)
        {
            // 播放完毕
            animator.speed = 0;
            isOVer = true;
                //销毁自身
            Invoke("Destroy",10f);

        }
    }

    private void Destroy()
    {
        ZombieManager.Instance.CreatUnDieZombie((int)currGrid.Point.y, transform.position);  //新建一个不死僵尸
                                                                              
        CancelInvoke();
        // 把自己放进缓存池
        PoolManager.Instance.PushObj(GameManager.Instance.GameConf.UnDieZombie_Diebody, gameObject); //尸体销毁
    }

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值