Hello im new to coding with c# and unity on the matter of fact. Im currently trying to add a bool that detects when enemies are “inrange” of my tower. For some reason my script is not detecting when enemies are in range.
public class tower : MonoBehaviour
{
public Transform Tower;
public Transform Enemypos;
public Transform arrow;
public static int TowerHealth = 10;
public static float TowerAttackSpeed = 0.2f;
public static float TowerAttackDmg = 2.0f;
public static int TowerRange = 12;
public bool inRange;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
float distance = Vector3.Distance (Tower.position, Enemypos.position);
inRange = (distance < TowerRange);
if (inRange == false )
{
Debug.Log("Test failed");
}
if (inRange == true)
{
Debug.Log("In range");
Instantiate(arrow, GameObject.FindGameObjectWithTag("Tower").transform.position, Quaternion.identity);
}
}