当前位置:网站首页>项目实训-火爆辣椒
项目实训-火爆辣椒
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
边栏推荐
- ffmpeg命令行常用参数
- CUMCM 2021-B:乙醇偶合制備C4烯烴(2)
- Upgrade the functions available for cpolar intranet penetration
- qt5. 8. You want to use SQLite in the 64 bit static library, but the static library has no method to compile the supporting library
- Excel·VBA自定义函数获取单元格多数值
- laravel 永远返回 JSON 响应
- 汇编语言 运行环境设置等教程链接整理
- 学习 Go 语言 0x01:从官网开始
- 初探 Lambda Powertools TypeScript
- 学习 Go 语言 0x07:《Go 语言之旅》中 Stringer 练习题代码
猜你喜欢

2022爱分析· 工业互联网厂商全景报告

SVN的使用:

升级cpolar内网穿透能获得的功能

R-Drop:更强大的Dropout正则方法

Laravel绑定钉钉群警报(php)

Excel · VBA custom function to obtain multiple cell values

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

After the MySQL router is reinstalled, it reconnects to the cluster for boot - a problem that has been configured in this host before

Get things technology network optimization - CDN resource request Optimization Practice

Usage of rename in cygwin
随机推荐
解析性能良好的机器人使用守则
Study notes of C [8] SQL [1]
语雀文档编辑器将开源:始于但不止于Markdown
Detailed explanation of MySQL creation stored procedure and function
mysql创建存储过程及函数详解
qt5. 8. You want to use SQLite in the 64 bit static library, but the static library has no method to compile the supporting library
Share two practical shell scripts
SVN的使用:
PyTorch 神经网络训练器
Constraintlayout layout
Three web components (servlet, filter, listener)
R-Drop:更强大的Dropout正则方法
CUMCM 2021-B:乙醇偶合制備C4烯烴(2)
PDMS soft lithography process
少儿编程结构的改变之路
GPU, CUDA,cuDNN三者的关系总结
学习 Go 语言 0x06:《Go 语言之旅》中 斐波纳契闭包 练习题代码
Mysql8. 0 installation guide
学习 Go 语言 0x04:《Go 语言之旅》中切片的练习题代码
More reliable model art than deep learning