当前位置:网站首页>Project training - clonemon
Project training - clonemon
2022-06-11 08:09:00 【azzin】
The preparation of the portal has been completed this time , The main function is in flying objects such as peas 、 When a bullet passes through a carambola
Code
The bullet
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Bullet : MonoBehaviour
{
private Rigidbody2D rigidbody;
private SpriteRenderer spriteRenderer;
// aggressivity
private int attackValue;
// Whether to hit
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;
// Picture modified to normal state
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; // Let the bullet become true Otherwise the bullet will be copied
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);
// Play the sound of zombies being attacked by Peas
else
AudioManager.Instance.PlayEFAudio(GameManager.Instance.GameConf.ZombieHurtForPea);
// Hurt zombies
coll.GetComponentInParent<ZombieBase>().Hurt(attackValue);
// Change to hit picture
spriteRenderer.sprite = GameManager.Instance.GameConf.Bullet1Hit;
// Pause your movement
rigidbody.velocity = Vector2.zero;
// whereabouts
rigidbody.gravityScale = 1;
// Destroy yourself
Invoke("Destroy", 0.5f);
}
}
private void Destroy()
{
isCloneDoor = false;
// Cancel deferred call
CancelInvoke();
// Put yourself in the cache pool
PoolManager.Instance.PushObj(GameManager.Instance.GameConf.Bullet1,gameObject);
}
}
Clone gate
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CloneDoor : PlantBase
{
public override float MaxHp => 300;
}
边栏推荐
- Detailed explanation of shift operator and bit operator in C language
- El expressions and JSTL
- Logical implication of functional dependence
- 学习《缠解论语》
- TypeScript-接口和类型别名异同
- JSP development model
- TypeScripy-类的基本使用
- DAMENG 用户管理
- C language - growth diary-04- preliminary exploration of local variables (local variables)
- Magnifying mirror rendering
猜你喜欢

用 Keras/TensorFlow 2.9 创建深度学习模型的方法总结

C language - growth diary-04- preliminary exploration of local variables (local variables)

The solution of "no startup device" after running Bochs

C language lesson 2

Sign in system design: how to draw the sign in function

图数据库无缝集成Tushare接口

Printing diamond of beginner C

SOCKET【5】- struct linger 用法
![Socket [5] - struct linker usage](/img/e5/bce5d89c61a3a4f89171734ca6ff8e.png)
Socket [5] - struct linker usage

Tidb cloud launched Google cloud marketplace, empowering global developers with a new stack of real-time HTAP databases
随机推荐
自定义ViewGroup的知识点总结-持续更新
TypeScript-分布式条件类型
DAMENG 数据库启停
Database connection pool and bdutils tool
Summary of embedded software interview questions
Typescript namespace
JSP development model
TiDB Cloud 上线 Google Cloud Marketplace,以全新一栈式实时 HTAP 数据库赋能全球开发者
2022.6.6 特长生模拟
C language lesson 2
860. lemonade change
Typescript distributed condition type
Activity中,View#postDelay会导致内存泄漏,但是不会影响Activity的生命周期执行。
Typescript configuring ts in koa and using koa router
A detailed explanation of one of the causes of dead loop caused by array out of bounds in C language
批量拼接字符串
[the most complete ENSP [installation diagram] in history!]
How to find the complementary sequence of digraph
空间几何
About static keyword