当前位置:网站首页>项目实训-火爆辣椒
项目实训-火爆辣椒
2022-04-23 11:23:00 【azzin】
火爆辣椒的逻辑和樱桃炸弹类似,其不同的是攻击范围是一整行,而且可以破坏雪橇车僵尸产生的冰
代码
火爆辣椒
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);
}
}
版权声明
本文为[azzin]所创,转载请带上原文链接,感谢
https://blog.csdn.net/azzin/article/details/124236545
边栏推荐
猜你喜欢

进程间通信 -- 消息队列

26. Delete duplicates in ordered array

Get things technology network optimization - CDN resource request Optimization Practice

Summary of the relationship among GPU, CUDA and cudnn

PDMS软光刻加工过程

MIT: label every pixel in the world with unsupervised! Humans: no more 800 hours for an hour of video

解读2022机器人教育产业分析报告

让中小学生在快乐中学习的创客教育

探究机器人教育的器材与教学

VM set up static virtual machine
随机推荐
进程间通信 -- 消息队列
Mysql排序的特性详情
解析社交性机器人对基础科学的作用
More reliable model art than deep learning
实践数据湖iceberg 第三十课 mysql->iceberg,不同客户端有时区问题
map<QString, bool> 的使用记录
Laravel绑定钉钉群警报(php)
Compress the curl library into a sending string of utf8 and send it with curl library
R-drop: a more powerful dropout regularization method
Explain in detail the pitfalls encountered in DTS due to the time zone problems of timestamp and datetime in MySQL
Excel·VBA自定义函数获取单元格多数值
PDMS软光刻加工过程
Who said you should know PS? This open-source artifact can also be pulled in batch, and the effect is outstanding!
Summary of the relationship among GPU, CUDA and cudnn
Excel · VBA array bubble sorting function
My creation anniversary
卷积层和池化层总结
解读机器人创造出来的艺术
MySQL sorting feature details
Learning go language 0x02: understanding slice