当前位置:网站首页>项目实训-克隆门
项目实训-克隆门
2022-06-11 08:05:00 【azzin】
本次完成了传送门的编写,主要作用是在飞行物如豌豆、杨桃子弹等经过的时候生成一个一样的子弹
代码
子弹
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Bullet : MonoBehaviour
{
private Rigidbody2D rigidbody;
private SpriteRenderer spriteRenderer;
// 攻击力
private int attackValue;
// 是否击中
private bool isHit;
public bool isCloneDoor=false;
private Grid currGrid;
private Vector3 offset = new Vector3(-0.4f, 0, 0);
public void Init(int attackValue,Vector2 pos)
{
transform.position = pos;
rigidbody = GetComponent<Rigidbody2D>();
spriteRenderer = GetComponent<SpriteRenderer>();
rigidbody.AddForce(Vector2.right*300);
this.attackValue = attackValue;
rigidbody.gravityScale = 0;
isHit = false;
// 修改成正常状态的图片
spriteRenderer.sprite = GameManager.Instance.GameConf.Bullet1Nor;
}
void Update()
{
currGrid = GridManager.Instance.GetGridByWorldPos(transform.position);
if (currGrid.currPlantBase == null) return;
if (currGrid.currPlantBase.name == "CloneDoor(Clone)" && !isCloneDoor)
{
isCloneDoor = true;
Bullet bullet = PoolManager.Instance.GetObj(GameManager.Instance.GameConf.Bullet1).GetComponent<Bullet>();
bullet.isCloneDoor = true; //让子弹也变成true 否则这个子弹也会被复制
bullet.Init(attackValue, transform.position+offset );
}
if (isHit) return;
if (transform.position.x>7.7F)
{
Destroy();
return;
}
transform.Rotate(new Vector3(0,0,-15f));
}
private void OnTriggerEnter2D(Collider2D coll)
{
if (coll.GetComponentInParent<ZombieBase>() == null) return;
if (isHit) return;
if (coll.tag == "Zombie")
{
isHit = true;
if(coll.GetComponentInParent<ZombieBase>().name=="BucketheadZombie(Clone)"|| coll.GetComponentInParent<ZombieBase>().name == "IceZombie(Clone)"
|| coll.GetComponentInParent<ZombieBase>().name == "ScreenDoorZombie(Clone)")
AudioManager.Instance.PlayEFAudio(GameManager.Instance.GameConf.SteelHurtByPea);
// 播放僵尸被豌豆攻击的音效
else
AudioManager.Instance.PlayEFAudio(GameManager.Instance.GameConf.ZombieHurtForPea);
// 让僵尸受伤
coll.GetComponentInParent<ZombieBase>().Hurt(attackValue);
// 修改成击中图片
spriteRenderer.sprite = GameManager.Instance.GameConf.Bullet1Hit;
// 暂停自身的运动
rigidbody.velocity = Vector2.zero;
// 下落
rigidbody.gravityScale = 1;
// 销毁自身
Invoke("Destroy", 0.5f);
}
}
private void Destroy()
{
isCloneDoor = false;
// 取消延迟调用
CancelInvoke();
// 把自己放进缓存池
PoolManager.Instance.PushObj(GameManager.Instance.GameConf.Bullet1,gameObject);
}
}
克隆门
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CloneDoor : PlantBase
{
public override float MaxHp => 300;
}
边栏推荐
- SylixOS SD设备驱动开发
- Method summary of creating deep learning model with keras/tensorflow 2.9
- TypeScript-接口和类型别名异同
- Tidb cloud launched Google cloud marketplace, empowering global developers with a new stack of real-time HTAP databases
- Shell编程笔记
- C. Managing history (greedy / hashing / thinking / good questions)
- Collation of basic knowledge of intermediate development of Andrews (for interview)
- Dameng user management
- C# 微信上传Form-data
- Getting started with bladed tutorial (video)
猜你喜欢

Summary of embedded software interview questions

TiDB Cloud 上線 Google Cloud Marketplace,以全新一棧式實時 HTAP 數據庫賦能全球開發者
![Socket [5] - struct linker usage](/img/e5/bce5d89c61a3a4f89171734ca6ff8e.png)
Socket [5] - struct linker usage

记一次忽略@SuppressLint(“NewApi“)提示引发的血案

【案例解读】医疗单据OCR识别助力健康险智能理赔

Black Qunhui dsm7.0.1 physical machine installation tutorial

Image data enhancement (translation, rotation, brightness transformation, flipping, adding Gaussian noise, scaling, cropping)

Collation of basic knowledge of intermediate development of Andrews (for interview)

Bladed入门教程(视频)

C language lesson 2
随机推荐
The solution of "no startup device" after running Bochs
DAMENG 数据库登陆
Use guidelines in constraintlayout to limit the maximum width of controls
TiDB Cloud 上線 Google Cloud Marketplace,以全新一棧式實時 HTAP 數據庫賦能全球開發者
如何做好空状态设计?来看这份全面总结
记一次忽略@SuppressLint(“NewApi“)提示引发的血案
TypeScript-在koa中配置TS和使用koa-router
TiDB Cloud 上线 Google Cloud Marketplace,以全新一栈式实时 HTAP 数据库赋能全球开发者
Closure and minimum dependency in database
How to output the percent sign "%" in printf function in C language
Socket [5] - struct linker usage
Training yolov4 CSP model using coco dataset
DAMENG 数据库启停
Xshell7 和 Xftp7要继续使用此程序,您必须应用最新的更新或者使用新版本
2022.6.7 special student simulation
安卓初中级开发基础知识整理(面试自用)
Bubble sorting with C language
TypeScript-接口和类型别名异同
Tidb cloud launched Google cloud marketplace, empowering global developers with a new stack of real-time HTAP databases
Printing diamond of beginner C