i’m trying to use a counter to be increased by one (one stands for one second)
when the ray is pointing to the enemy object consistently (say for 4 seconds)
then we have a missile lock.
iv’e tried to use if statement inside the update, but it increases the counter only once while pointing on the enemy object.
also tried to use while loop inside update _ ,but it is behaving like an infinite loop.
private var lockedTarget : Transform;
var missileLock : boolean = false;
var missileLockTimer : int = 0;
var lockSound : AudioClip;
var missileFire : AudioClip;
private var ray : Ray;
private var hit : RaycastHit;
function Update ()
{
ray = Camera.main.ScreenPointToRay(Input.mousePosition);
if(Physics.Raycast(ray, hit) && SpawnRightFlag == true)
{
if(hit.collider.tag.Equals("ptr80") && missileLock == false)
{
audio.PlayOneShot(lockSound);
missileLock = true;
if(hit.collider.tag.Equals("ptr80"))//here tried while instead of if
{
missileLockTimer += 1;
}
if(missileLockTimer >= 4)
{
lockedTarget = hit.collider.transform;
}
}
else if(!hit.collider.tag.Equals("ptr80"))
{
audio.Stop();
missileLock = false;
}
var rPoint: Vector3 = hit.point;
SpawnRight.transform.LookAt(rPoint);
}
}