I have created this script:
#pragma strict
var player : Transform;
var playerScript : PlayerScript;
var attackDistance : float = 20;
function Update () {
var distance = Vector3.Distance (player.position, transform.position);
if (distance <= attackDistance) {
Attack ();
}
}
function Attack () {
playerScript.health -= 30;
Debug.Log (playerScript.health);
yield WaitForSeconds (2);
}
But the yield wait for seconds doesn’t delay the function.