- Home /
Question by
JuggZii · Mar 01 at 03:38 AM ·
c#scripting problem
scripting problem trying to create a "inRange" condition
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 == true)
{
Debug.Log("In range");
Instantiate(arrow, GameObject.FindGameObjectWithTag("Tower").transform.position, Quaternion.identity);
}
}
Comment
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Unity 3D Player Follow 0 Answers
Wave Spawner not working |Does not detect if an object is destroyed 1 Answer
Swipe incorrectly working 0 Answers