Здравствуйте, у меня есть код, который перемещает мою основную камеру в другие позиции игровых объектов, когда я нажимаю кнопку, как если бы я нажимал кнопку 1, она будет двигаться в направлении объекта 1, то же самое для кнопок 2 и 3. Теперь в моем коде у меня есть логическое значениеназванный как флаг, который имеет значение true в функции обновления, тогда у меня есть несколько общедоступных функций для нескольких кнопок. Теперь, когда я нажимаю любую кнопку, логическое значение становится истинным и остается истинным, что вызывает дрожание камеры, потому что логическое значение постоянно обновляется, скажите, пожалуйста, когда моя камерадостигает конечной позиции, флаг логический становится ложным, и когда я снова нажимаю другую кнопку, я снова становлюсь истинным, вот мой код
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class camMOVE : MonoBehaviour {
public Transform handleview;
public Transform pressureview;
public Transform wallview;
public Transform sechandleview;
public Transform pressuretwoview;
public Transform switchview;
public GameObject handlebtn;
public GameObject pressurebtn;
public GameObject wallbtn;
public GameObject handletwobtn;
public GameObject pressuretwobtn;
public GameObject switchbtn;
public GameObject parentobj;
Animator anim;
public float transitionSPEED;
Transform currentVIEW;
private bool flag = false;
Vector3 currentangel;
public List<GameObject> modelparts;
private void Start(){
handlebtn.SetActive (true);
pressurebtn.SetActive (false);
wallbtn.SetActive (false);
handletwobtn.SetActive (false);
pressuretwobtn.SetActive (false);
switchbtn.SetActive (false);
anim = parentobj.GetComponent<Animator> ();
anim.SetBool ("start", true);
//currentVIEW = handleview;
foreach (GameObject obj in modelparts) {
obj.GetComponent<BoxCollider> ().enabled = false;
}
}
private void Update(){
if (flag == true) {
transform.position = Vector3.Lerp (transform.position,
currentVIEW.position, Time.deltaTime * transitionSPEED);
currentangel = new Vector3 (Mathf.LerpAngle
(transform.rotation.eulerAngles.x, currentVIEW.transform.rotation.eulerAngles.x, Time.deltaTime * transitionSPEED),
Mathf.LerpAngle (transform.rotation.eulerAngles.y, currentVIEW.transform.rotation.eulerAngles.y, Time.deltaTime * transitionSPEED),
Mathf.LerpAngle (transform.rotation.eulerAngles.z, currentVIEW.transform.rotation.eulerAngles.z, Time.deltaTime * transitionSPEED));
transform.eulerAngles = currentangel;
}
}
public void Handleview(){
currentVIEW = handleview;
handlebtn.SetActive (false);
flag = true;
}
public void Pressureview(){
currentVIEW = pressureview;
pressurebtn.SetActive (false);
flag = true;
}
public void Wallview(){
currentVIEW = wallview;
wallbtn.SetActive (false);
flag = true;
}
public void Secondhandleview(){
currentVIEW = sechandleview;
handletwobtn.SetActive (false);
flag = true;
}
public void Pressuretwoview(){
currentVIEW = pressuretwoview;
pressuretwobtn.SetActive (false);
flag = true;
}
public void Switchview(){
currentVIEW = switchview;
switchbtn.SetActive (false);
flag = true;
}
}