i have a ai script but i cannot assign the target variable. i dont know whats wrong could someone tell me please? here is the code
var IsPlayingOtherAnim = false;
var Distance;
var Player : GameObject;
var lookAtDistance = 25.0;
var ChaseRange = 15.0;
var attackRange = 1.5;
var moveSpeed = 5.0;
var Damping = 6.0;
var AttackRepeatTime = 1;
static var TheDamage = 10;
private var attackTime : float;
var controller : CharacterController;
var Gravity : float = 20;
private var MoveDirection : Vector3 = Vector3.zero;
function start ()
{
attackTime = Time.time;
Player = GameObject.Find("Player");
}
function Update ()
{
Distance = Vector3.Distance(Player.position, transform.position);
if (Distance < lookAtDistance)
{
lookAt();
}
if (Distance > lookAtDistance)
{
renderer.material.color = Color.green;
}
if (Distance < attackRange)
{
Attack();
}
else if (Distance < ChaseRange)
{
Chase ();
}
}
function lookAt ()
{
renderer.material.color = Color.yellow;
var rotation = Quaternion.LookRotation(Player.position - transform.position);
transform.rotation = Quaternion.Slerp(transform.rotation, rotation, Time.deltaTime * Damping);
}
function Chase ()
{
renderer.material.color = Color.red;
moveDirection = transform.forward;
moveDirection *= moveSpeed;
moveDirection.y -= Gravity * Time.deltaTime;
controller.Move(moveDirection * Time.deltaTime);
}
function Attack ()
{
if (Time.time > attackTime)
{
Player.SendMessage("ApplyDammage", TheDamage, SendMessageOptions.DontRequireReceiver);
Debug.Log ("the enemy has attacked");
attackTime = Time.time + AttackRepeatTime;
}
}
function ApplyDamage ()
{
ChaseRange = 30;
moveSpeed = 4;
lookAtDistance = 40;
}