问题描述
这段代码对我来说毫无意义,这可能是我这边的愚蠢错误。但是,如果有人可以解释我所犯的错误,那就太好了。
using System.Collections;
using UnityEngine;
public class Tower : MonoBehavIoUr
{
[Serializefield] Transform objectToPan = default;
[Serializefield] Transform enemyTarget = default;
[Serializefield] ParticleSystem BulletParticles = default;
[Serializefield] Enemydamage StopIfDead = default; //Another Script
bool isNotDead = true;
const int maxShootRange = 30;
void Update()
{
TowerShoots();
}
void TowerShoots()
{
float distanceBetweenBoth = Vector3.distance(objectToPan.transform.position,enemyTarget.transform.position);
if (distanceBetweenBoth >= maxShootRange)
{
BulletParticles.Play();
}
if (StopIfDead.isDead == true)
{
WhenDead();
}
}
void WhenDead()
{
const int DeathRota = 0;
isNotDead = false;
BulletParticles.Stop();
objectToPan.transform.rotation = Quaternion.Euler(DeathRota,DeathRota,DeathRota);
}
}
我注意到的第一件事是
if(distanceBetweenBoth >= maxShootRange)
{
//Stuff
}
这不是说 if 距离大于或等于播放粒子。问题是,如果距离大于maxShootRange(30),则不会在30以上拍摄。问题是,如果这两个对象之间的距离大于或等于maxShootRange(30), ,那么它将不会拍摄比maxShootRange更远的东西。它实际上在30岁及以下拍摄。我尝试了许多不同类型的方法,但似乎都没有。我尝试用敌人目标切换objectToPan的顺序。但是它基本上做同样的事情。如果我发表其他声明说不要开枪。比代码完全停止射击。我试图打开和关闭PlayOnAwake,看看效果如何。但是现在我不确定。
else
{
//Stop the Bullets
}
如果您需要有关“粒子系统”设置和内容的更多信息,请问我。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)