当前位置:网站首页>项目实训-火爆辣椒
项目实训-火爆辣椒
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
边栏推荐
- 解读机器人编程课程的生物认知度
- 学习 Go 语言 0x07:《Go 语言之旅》中 Stringer 练习题代码
- Redis optimization series (II) redis master-slave principle and master-slave common configuration
- 博客文章导航(实时更新)
- Summary of the relationship among GPU, CUDA and cudnn
- AcWing 1874. 哞加密(枚举,哈希)
- After the MySQL router is reinstalled, it reconnects to the cluster for boot - a problem that has been configured in this host before
- Mysql中一千万条数据怎么快速查询
- Learn go language 0x04: Code of exercises sliced in go language journey
- My creation anniversary
猜你喜欢
实践数据湖iceberg 第三十课 mysql->iceberg,不同客户端有时区问题
Laravel绑定钉钉群警报(php)
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
升级cpolar内网穿透能获得的功能
Redis optimization series (II) redis master-slave principle and master-slave common configuration
Excel · VBA array bubble sorting function
Constraintlayout layout
初探 Lambda Powertools TypeScript
GPU, CUDA,cuDNN三者的關系總結
MIT: label every pixel in the world with unsupervised! Humans: no more 800 hours for an hour of video
随机推荐
Mysql database transaction example tutorial
My creation anniversary
Detailed introduction to paging exploration of MySQL index optimization
Laravel增加自定义助手函数
Software testers, how to mention bugs?
laravel-admin表单验证
nacos基础(8):登录管理
MySQL failed to insert the datetime type field without single quotation marks
Jupyter lab top ten high productivity plug-ins
Oracle连通性测试小工具
妊娠箱和分娩箱的区别
Who said you should know PS? This open-source artifact can also be pulled in batch, and the effect is outstanding!
系统编程之高级文件IO(十三)——IO多路复用-select
防止web项目中的SQL注入
GPU, CUDA,cuDNN三者的关系总结
面向全球市场,PlatoFarm今日登录HUOBI等全球四大平台
After the MySQL router is reinstalled, it reconnects to the cluster for boot - a problem that has been configured in this host before
详解MySQL中timestamp和datetime时区问题导致做DTS遇到的坑
Excel·VBA自定义函数获取单元格多数值
PDMS软光刻加工过程