火爆辣椒的逻辑和樱桃炸弹类似,其不同的是攻击范围是一整行,而且可以破坏雪橇车僵尸产生的冰
代码
火爆辣椒
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);
}
}