Well I got stuck in delaying an action here on my script, for some reason even though it does run the function it doesnt really yield or delay until the secs have passed here is the code.
tried using Wait(); so it should wait until all has been done but still doesnt wait the secs marked, any hint?
#pragma strict
var health : float = 100;
var attack : boolean = false;
var Dis : float = 5;
var GOspeed : float = 10;
var damage : float = 5;
function Start (){
attack = false;
}
function LateUpdate(){
if(attack == false)
{
transform.Translate(GOspeed * Time.deltaTime,0,0);
}
if(health <= 0)
{
Destroy(gameObject);
}
var hit : RaycastHit;
var layerMask = 1 << 9;
if (Physics.Raycast (transform.position, Vector3.right, hit, Dis, layerMask))
{
var target : Collider;
target = hit.collider;
if(hit.distance <= Dis)
{
attack = true;
print("attacking!");
Debug.DrawLine (transform.position, hit.point);
Wait();
}
}
else if(hit.collider == null)
{
attack = false;
}
}
function ApplyDamage ( damage : float )
{
health -= damage;
yield WaitForSeconds (5);
}
function Wait (){
yield WaitForSeconds (3);
}