当前位置:网站首页>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;
}
边栏推荐
猜你喜欢

Summary of evaluation index knowledge points in target detection: summary of IOU cross overlap unit and map/ap/tp/fp/np

Alchemy experience (model training of deep learning) the necessity of timely adjusting training parameters for some situations (the adjustment of learning rate LR is the primary) summarizes some metho

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

【 史上最全的ENSP【安装图解】!】

2022.6.6 extra long growth simulation

How to do well in empty state design? Look at this comprehensive summary

C language - Growth Diary -03- function definition and function prototype declaration

Zero foundation self-study SQL course | union joint query

TiDB Cloud 上线 Google Cloud Marketplace,以全新一栈式实时 HTAP 数据库赋能全球开发者

How to find the complementary sequence of digraph
随机推荐
Method summary of creating deep learning model with keras/tensorflow 2.9
Use guidelines in constraintlayout to limit the maximum width of controls
TypeScript-键盘映射
进程控制:进程等待(回收子进程)
Shell编程笔记
2022.6.6 extra long growth simulation
Request request object and response response object
Record a murder case caused by ignoring the @suppresslint ("newapi") prompt
Semiconductor memory classification
JSP technology: JSP overview, JSP basic syntax, JSP instructions, JSP implicit objects, JSP action elements
[untitled] Weng_ C lesson 1
2022.6.7 特长生模拟
How to do well in empty state design? Look at this comprehensive summary
Planning tasks for continuous automated testing
Three expressions of integers and their storage in memory
Lesson 1 about Xiaobai's C language
Printing diamond of beginner C
Bubble sorting with C language
签到体系设计:签到功能该怎么画
TiDB Cloud 上線 Google Cloud Marketplace,以全新一棧式實時 HTAP 數據庫賦能全球開發者