Delaying script

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?

:face_with_spiral_eyes:

#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);
}

In your original code, simply use Wait() is simply call a function, then move to next line of code.

if you want the execution pause at Wait, u should use yield Wait() ( it is not possible using that in Update() thought, is a bit tricky ).

You can refer to this script if u really want to yield in Update. http://www.unifycommunity.com/wiki/index.php?title=CoUpdate

–TwisterK