项目实训-火爆辣椒

火爆辣椒的逻辑和樱桃炸弹类似,其不同的是攻击范围是一整行,而且可以破坏雪橇车僵尸产生的冰

代码

火爆辣椒

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

public class Pepper : PlantBase
{
    public override float MaxHp =>300;

    protected override int attackValue => 1800;

    //火焰
    private Vector3 boomoffset = new Vector3(0, 0.3f, 0);


    protected override void OnInitForPlace()
    {
        StartCoroutine(CheckBoom());
    }

    /// <summary>
    /// 检测爆炸
    /// </summary>
    /// <returns></returns>
    IEnumerator CheckBoom()
    {


        while (true)
        {
            yield return new WaitForSeconds(0.05f);
            if (animator.GetCurrentAnimatorStateInfo(0).normalizedTime>=1)
            {
                // 爆炸
                Boom();
            }
        } 
    }
    private void Boom()
    {
        // 播放爆炸音效
        AudioManager.Instance.PlayEFAudio(GameManager.Instance.GameConf.Boom);
        // 找到可以被我攻击的敌人,并且附加伤害
        List<ZombieBase> zombies = ZombieManager.Instance.GetZombies((int)currGrid.Point.y);
        if (zombies == null) return;
        for (int i = 0; i < zombies.Count; i++)
        {
            zombies[i].BoomHurt(attackValue,zombies[i].name);
        }
        // 找到我所在的网格的一横行,全部设置为无冰
        List<Grid> grids = GridManager.Instance.GetGrids((int)currGrid.Point.y);
        if (grids == null) return;
        for (int i = 0; i < grids.Count; i++)
        {
            grids[i].HaveIce = false;
        }


        // 生成攻击特效
        PepperFire pepperFire = PoolManager.Instance.GetObj(GameManager.Instance.GameConf.PepperFire).GetComponent<PepperFire>();
        Vector3 PepperFirePlace = new Vector3(-2.0f, transform.position.y+0.3f, 0);               //在当前辣椒的y坐标生成火焰,x坐标固定在屏幕中间
        pepperFire.Init(PepperFirePlace);
        // 自身死亡
        Dead();

    }
}

火爆辣椒火焰

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

public class PepperFire : BaseEFObj
{
    public override string AnimationName => "PepperFire";

    public override GameObject PrefabForObjPool => GameManager.Instance.GameConf.PepperFire;

    protected override float WaitTime => 0.05f;
}

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", 40f);
        }
        if (currGrid.HaveIce == false) Destroy();    //如果当前网格没有冰 立刻销毁冰(火爆辣椒通过这个逻辑去除冰)
    }

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





}

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值