This code makes no sense to me, it's probably stupid mistake on my side. But if someone could explain the error I made, that would be great.
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);
}
}
First major thing I noticed is that
if(distanceBetweenBoth >= maxShootRange)
{
//Stuff
}
Doesn't this mean that, if the distance is greater, or equal to, than play the particles. The problem is that, if the distance is greater than the maxShootRange (30), than it won't shoot above 30. The problem is that if the distance between these two object is greater than, or equal to, the maxShootRange (30), than it won't shoot something that is further than maxShootRange. It actually shoots under the 30 and below. I have tried many different type of ways, non of which seem to work. I tried to switch the order of objectToPan with enemyTarget. Yet it basically does the same thing. If I make an else statement saying not to shoot. Than the code completely stops shooting. I tried to turn on and off PlayOnAwake and see what effect that had. But now I am not sure.
else
{
//Stop the Bullets
}
If you need more information about the Particle System settings and stuff, ask me.
Aucun commentaire:
Enregistrer un commentaire