I’m a little confused, I’m trying to play this coroutine “moveWeaponIn()” once, it moves the weapon to where I want it but just keeps looping, can someone please tell me what I’m doing wrong, thanks.
#pragma strict
var zoom : int = 20;
var normal : int = 60;
var smooth : float = 5;
private var globalVars : GameObject; // var for the GameObject with the GlobalVars on
function Awake(){
globalVars = GameObject.Find("Global Vars"); // Find the gameObject with the GlobalVars attached to it
}
function Start(){
}
function Update () {
if(globalVars.GetComponent(GlobalVars).weaponZoomed){
camera.fieldOfView = Mathf.Lerp(camera.fieldOfView,zoom,Time.deltaTime*smooth);
moveWeaponIn();
}else{
camera.fieldOfView = Mathf.Lerp(camera.fieldOfView,normal,Time.deltaTime*smooth);
}
}
function moveWeaponIn(){
var pointA = globalVars.GetComponent(GlobalVars).currentWeapon.transform.position;
var pointB = globalVars.GetComponent(GlobalVars).currentWeapon.transform.position + Vector3(-0.25,0.05,0);
while (true) {
yield MoveObject(globalVars.GetComponent(GlobalVars).currentWeapon, pointA, pointB, 1.0);
}
}
function MoveObject (thisTransform : Transform, startPos : Vector3, endPos : Vector3, time : float) {
var i = 0.0;
var rate = 1.0/time;
while (i < 1.0) {
i += Time.deltaTime * rate;
thisTransform.position = Vector3.Lerp(startPos, endPos, i);
yield;
}
}