I tried to find the answer for 2 days but I can’t
Question: I want when the “Player” comes near the Turret, I will have a report “in” and far away is “out”
In this script, when I come near the Turret, report “in” appears, and far away is “out” but when I go near again, I can’t have report “in”. Can someone please help me here?
Thanks in advance, Regards
Can someone please help me here?
var target: Transform;
var range = 10.0;
function Awake()
{
target = GameObject.FindWithTag("Player").transform;
}
function Update()
{
CanAttackTarget();
if (target && CanAttackTarget())
{
var targetRotation = Quaternion.LookRotation(transform.position - target.position,Vector3.up);
transform.rotation=Quaternion.Slerp(transform.rotation, targetRotation, Time.deltaTime* 2);
}
}
function CanAttackTarget()
{
if(Vector3.Distance(transform.position, target.position)>range)
{
print("out");
return false;
}
print("in");
return true;
}