当前位置:网站首页>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;
}
边栏推荐
- Post - form data of interface test
- C language to achieve a simple game - minesweeping
- C. Managing history (greedy / hashing / thinking / good questions)
- Typescript configuring ts in koa and using koa router
- Post - payload of interface test
- Detailed explanation of shift operator and bit operator in C language
- Use of Excel to XML tool of TestLink
- Simple use of string
- Magnifying mirror rendering
- TypeScript-键盘映射
猜你喜欢

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

About static keyword
![[untitled] Weng_ C lesson 1](/img/4e/41876093ef6b6a38909832f89e1495.jpg)
[untitled] Weng_ C lesson 1

如何做好空状态设计?来看这份全面总结

批量拼接字符串

Batch splice string

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

(transformation) tree, binary tree and forest transformation principle

A detailed explanation of one of the causes of dead loop caused by array out of bounds in C language

签到体系设计:签到功能该怎么画
随机推荐
Bubble sorting with C language
放大镜子效果图
Tidb Cloud est en ligne sur le marché Google Cloud pour permettre aux développeurs du monde entier d'utiliser une nouvelle pile de bases de données htap en temps réel
关于网络知识的50个问答题,你能答对几个?
Long dialogue in June 2017
Layout of code setting constraintlayout_ constraintDimensionRatio
Bladed入門教程(視頻)
(transformation) tree, binary tree and forest transformation principle
Typescript type protection
Dameng database startup and shutdown
Getting started with bladed tutorial (video)
134. 加油站
Several ways to avoid concurrent modification exceptions of lists
The solution of "no startup device" after running Bochs
Solve cannot import name 'multiheadattention' from 'tensorflow keras. layers‘
Understanding of Poisson distribution and Poisson process and Erlang distribution and their relations (important theories in queuing theory and operational research)
TiDB Cloud 上線 Google Cloud Marketplace,以全新一棧式實時 HTAP 數據庫賦能全球開發者
图数据库无缝集成Tushare接口
forEach 中 return 和 for 中 break
2022.6.6 特长生模拟