当前位置:网站首页>项目实训-克隆门
项目实训-克隆门
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;
}
边栏推荐
- [untitled] Weng_ C lesson 1
- Return in foreach and break in for
- [transfer] two-way merging and sorting of C language
- The solution of "no startup device" after running Bochs
- Logical implication of functional dependence
- Space geometry
- 2022.6.7 特长生模拟
- El expressions and JSTL
- Collation of basic knowledge of intermediate development of Andrews (for interview)
- Layout of code setting constraintlayout_ constraintDimensionRatio
猜你喜欢

放大镜子效果图
![Socket [5] - struct linker usage](/img/e5/bce5d89c61a3a4f89171734ca6ff8e.png)
Socket [5] - struct linker usage

C language - Growth Diary -02- function

How to find the complementary sequence of digraph

Summary of embedded software interview questions

C# 微信上传Form-data

C language to achieve three piece chess (not artificial mental retardation ha ha ha)

Xshell7 和 Xftp7要继续使用此程序,您必须应用最新的更新或者使用新版本

Zero foundation self-study SQL course | union joint query

C language - Growth Diary -01- count primes and sum
随机推荐
A detailed explanation of one of the causes of dead loop caused by array out of bounds in C language
TypeScript-声明合并
Storage of floating point in memory
Typescript interface and type alias similarities and differences
Note: JDBC
C language to achieve a simple game - minesweeping
Use guidelines in constraintlayout to limit the maximum width of controls
Three expressions of integers and their storage in memory
El expressions and JSTL
Figure seamless database integration tushare interface
Typescript recognizable Union
Switch statement
Sign in system design: how to draw the sign in function
使用特殊字符拼接字符串“+“
Methods to improve training speed in deep learning and techniques to reduce video memory (suitable for entry-level trick without too many computing resources)
860. 柠檬水找零
使用 COCO 数据集训练 YOLOv4-CSP 模型
Post - form data of interface test
Image processing operation record
Sort - merge sort