i want my turret to only turn when i am in range 10 ft but the script makes it look at me no matter where i am can someone please help her is my script
var target : Transform;
var range = 10.0;
function Awake()
{
if(!target)
{
target = GameObject.FindWithTag(“Player”).transform;
}
}
function Update ()
{
if(target && CanAttackTarget)
{
var target : Transform;
var range = 10.0;
var isSeeTarget = false; //<-- add this.
function Awake()
{
if(!target)
{
target = GameObject.FindWithTag("Player").transform;
}
}
function Update ()
{
isSeeTarget = CanAttackTarget(); //<-- add this, and to chack the target is in the range.
if(target && isSeeTarget) //<-- add this, and to chack is the isSeeTarget = true?
{
//transform.LookAt(LookAtTarget);
var targetRotation = Quaternion.LookRotation(target.position - transform.position, Vector3.up);
transform.rotation = Quaternion.Slerp(transform.rotation, targetRotation, Time.deltaTime * 1.5);
}
}
function CanAttackTarget() : boolean //<-- add the boolean to the function.
{
if(Vector3.Distance(transform.position, target.position) > range)
{
return false;
}
return true;
}