using System.Collections; using System.Collections.Generic; using UnityEngine; public class ActionButton : MonoBehaviour { /// /// ¾Ö´Ï¸ÞÀÌ¼Ç ½ÇÇà ¿©ºÎ /// public bool Run; /// /// ¾Ö´Ï¸ÞÀÌ¼Ç ¼Óµµ /// public float Speed =1; /// /// ¾Ö´Ï¸ÞÀÌ¼Ç ¸ñÇ¥ ȸÀü°ª(Euler) ¶Ç´Â ¸ñÇ¥ ÁÂÇ¥ /// public Vector3 TargetRot; public bool isFixed = false; public float waitForSecond = 0.5f; private Vector3 targetPos; private Vector3 initPos; private float t; /// /// ¾Ö´Ï¸ÞÀÌ¼Ç Á¾·á ¿©ºÎ /// private bool isEnd; /// /// ÄÚ·çÆ¾ÀÌ ½ÃÀÛÇß´ÂÁö ¿©ºÎ /// private bool isStart = false; /// /// ¾Ö´Ï¸ÞÀÌ¼Ç Á¾·á¸¦ ½ÃÀÛ°ªÀ¸·Î(VR¿¡¼­¸¸) /// public bool VREndStart; void Start() { initPos = transform.localPosition; Initialize(); } void Initialize() { if (VREndStart && SceneTypeManager.Inst.IsVRMode) { EndInit(); } else { Init(); } } void EndInit() { transform.localPosition = targetPos; isEnd = true; } void Init() { transform.localPosition = initPos; isEnd = false; } public void Play() { if (Run) { isEnd = !isEnd; t = 0; } Run = true; } void InitValues(bool end) { Run = false; isEnd = end; t = 0; } void Update() { if (Run) { t += Speed * Time.deltaTime; if (!isFixed) { if(!isEnd && !isStart) { isStart = true; StartCoroutine(MoveEndAndInit()); } } else { if (isEnd) { // Ãʱâ ÁÂÇ¥±îÁö ¾Ö´Ï¸ÞÀÌ¼Ç MoveInitPos(); } else { // ¸ñÇ¥ ÁÂÇ¥±îÁö ¾Ö´Ï¸ÞÀÌ¼Ç MoveEndPos(); } } } } private void MoveEndPos() { transform.localPosition = Vector3.Lerp(transform.localPosition, targetPos, t); if (transform.localPosition == targetPos) { InitValues(true); } } private void MoveInitPos() { transform.localPosition = Vector3.Lerp(transform.localPosition, initPos, t); if (transform.localPosition == initPos) { InitValues(false); } } IEnumerator MoveEndAndInit() { MoveEndPos(); yield return new WaitForSeconds(waitForSecond); MoveInitPos(); isStart = false; } }