项目实训2022-4-21(雪橇车僵尸)

本次完成雪橇车僵尸

导入素材,创建三个预制体分别为雪橇车僵尸、雪橇车爆炸,雪橇车僵尸的冰,然后创建动画

代码:

雪橇车僵尸

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

public class IceZombie : ZombieBase
{
    protected override int MaxHP => 800;

    protected override float speed => 4;

    protected override float attackValue => 100000;


    protected override bool isSpecial => true;

    protected override Vector2 offset => new Vector2(-1.35f, -0.232f);
    protected override GameObject Prefab => GameManager.Instance.GameConf.IceZombie;

    private Vector2 IceOffset = new Vector2(-1f, -0.128f); //产生的冰的偏移

    private float currPoint = 0;   //为了一个格子只产生一个冰


    public override void SpecialMove()
    {
      
        // 如果当前网格为空跳过移动检测
        if (currGrid == null) return;
        currGrid = GridManager.Instance.GetGridByWorldPos(transform.position + (Vector3)offset);


        // 当前网格中有植物 并且 他在我的左边 并且距离很近
        if (currGrid.HavePlant       
            && currGrid.CurrPlantBase.transform.position.x < transform.position.x + ((Vector3)offset).x
            && transform.position.x + ((Vector3)offset).x - currGrid.CurrPlantBase.transform.position.x < 0.3f)
        {
            //如果是地刺的话 地刺和僵尸同时死亡
            if (currGrid.currPlantBase.name == "Spike(Clone)") { currGrid.currPlantBase.Dead(); State = ZombieState.Dead; }
            else
            {
                currGrid.currPlantBase.Dead();
            }
            return;
        }


        //每走一个格子产生冰,连在一起
        if ( (currGrid.Point.x == 7 || currGrid.Point.x == 6 || currGrid.Point.x == 5 || currGrid.Point.x == 4 || 
            currGrid.Point.x == 3 || currGrid.Point.x == 2 || currGrid.Point.x == 1 || currGrid.Point.x == 0) &&currPoint!= currGrid.Point.x)
        {
            currPoint = currGrid.Point.x;
            Ice ice = PoolManager.Instance.GetObj(GameManager.Instance.GameConf.Zombie_Ice).GetComponent<Ice>();
            ice.Init(transform.position+(Vector3)IceOffset);
            
        }


        // 如果我在最左边的网格 并且 我已经越过了它
        else if (currGrid.Point.x == 0 && currGrid.Position.x - transform.position.x - ((Vector3)offset).x > 1f)
        {
            // 我们要走向终点 - 房子
            Vector2 pos = transform.position + (Vector3)offset;
            Vector2 target = new Vector2(-9.17f, -1.37f);
            Vector2 dir = (target - pos).normalized * 3f;
            transform.Translate((dir * (Time.deltaTime / 1)) / speed);

            // 如果我距离终点很近,意味着游戏结束
            if (Vector2.Distance(target, pos) < 0.05f)
            {
                // 触发游戏结束
                LVManager.Instance.GameOver();
                //BOSSLVmanager.Instance.GameOver();
            }
            return;
        }
        transform.Translate((new Vector2(-1.33f, 0) * (Time.deltaTime / 1)) / speed);
    }


    public override void InitZombieHpState()
    {
        zombieHpState = new ZombieHpState(
           0,
           new List<int>() { MaxHP, 600,300,100},
           new List<string>() { "IceZombieWalk", "IceZombieWalk1", "IceZombieWalk2", "IceZomBieDie" },
           new List<string>() { "" ,"","",""},
           new List<UnityAction>() { CheckState, CheckState, CheckState,CheckState }  //检测状态 用来改变动画
           );
    }

    public override void OnDead()
    {
        if (!isSpecialDie)  //如果不是特殊死法
        {// 创建一个死亡身体
            Zombie_Car car = PoolManager.Instance.GetObj(GameManager.Instance.GameConf.Zombie_Car).GetComponent<Zombie_Car>();
            car.Init(animator.transform.position+(Vector3)offset);
        }
    }


}

雪橇车僵尸的冰

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

public class Ice : MonoBehaviour
{
    private Grid currGrid;
    private Animator animator;
    protected bool isOVer;
    public void Init(Vector2 pos, string animationName = null)
    {
        animator = GetComponent<Animator>();
        transform.position = pos;
        isOVer = false;                        //动画播放完成
        animator.speed = 1;
        animator.Play(animationName, 0, 0);
        currGrid = GridManager.Instance.GetGridByWorldPos(pos);   //根据当前位置获取一个网格
        currGrid.HaveIce = true;                                       //该网格有冰
    }

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

    private void Destroy()
    {
        currGrid.HaveIce = false;
        CancelInvoke();
        // 把自己放进缓存池
        PoolManager.Instance.PushObj(GameManager.Instance.GameConf.Zombie_Ice, gameObject);
    }




}

雪橇车僵尸的冰车

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

public class Zombie_Car : BaseEFObj
{
    protected override float WaitTime => 0.3f;

    public override string AnimationName => "Car_Die";
    public override GameObject PrefabForObjPool => GameManager.Instance.GameConf.Zombie_Car;

}

GameConf

    [Tooltip("雪橇车僵尸的车")]
    public GameObject Zombie_Car;
    [Tooltip("雪橇车僵尸的冰")]
    public GameObject Zombie_Ice;
    [Tooltip("雪橇车僵尸")]
    public GameObject IceZombie;

Gird

    //是否有冰
    public bool HaveIce=false;

Chomper

       if (zombie.name=="IceZombie(Clone)" || zombie.transform.position.x < transform.position.x || zombie.transform.position.x - transform.position.x > 4.5f) return;

PlantCard

           // 如果我距离网格比较近,并且它没有植物 并且没有冰 需要在网格上出现一个透明的植物
            if (grid.HavePlant==false&&grid.HaveIce==false&& Vector2.Distance(mousePoint, grid.Position) <1.5)
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值