Hi guys i have bin stuck on his for a few weeks and cant seem to get round it. I have my attack script and cant seem to get the attack animation in place so it doesn’t conflict with my other animations and only runs when I am in range. i will post my script and any hints and tips would be really appreciated
var target : GameObject;
var attackTimer : float;
var coolDown : float;
function Start()
{
attackTimer = 0.0;
coolDown = 1.5;
}
function Timer ()
{
if(attackTimer > 0)
attackTimer -= Time.deltaTime;
if(attackTimer < 0)
attackTimer = 0;
if(attackTimer == 0)
{
Attack();
attackTimer = coolDown;
}
}
function Attack()
{
var distance = Vector3.Distance(target.transform.position, transform.position);
var dir : Vector3 = (target.transform.position - transform.position).normalized;
var direction = Vector3.Dot(dir, transform.forward);
Debug.Log(direction);
if(distance <= 2.5 && direction > 0.3)
{
var ph : PlayerHealth = target.GetComponent("PlayerHealth");
ph.AdjustCurrentHealth(-10);
}
}