using DG.Tweening; using System.Collections; using System.Collections.Generic; using UnityEngine; public class UIMove : MonoBehaviour { public Transform Head; public bool isMove; private Transform target; public Transform headpos; // Start is called before the first frame update void Start() { isMove = false; // SettingEditor(headpos); // StartCoroutine(Func()); } //private void Update() //{ // if(isMove) // { // //if(Mathf.Abs( Vector2.Distance(new Vector2(transform.position.x,transform.position.z),new Vector2(Head.position.x,Head.position.z)))>0.3f) // //transform.DOMove(new Vector3(Head.position.x, transform.position.y, Head.position.z), 0.1f); // if(Mathf.Abs(Head.transform.eulerAngles.x)<45) // { // transform.position = new Vector3(Head.position.x, transform.position.y, Head.position.z); // } // } //} //IEnumerator Func() //{ // while (true) // { // yield return new WaitForSeconds(1.0f); // first // if (isMove) // { // Vector2 pos = (new Vector2(target.position.x, target.position.z) + new Vector2(Head.parent.position.x, Head.parent.parent.position.z)) * 0.5f; // transform.DOMove(new Vector3(pos.x,-0.35f,pos.y), 0.9f); // } // // transform.position = Vector3.Lerp(transform.position, SvrManager.Instance.head.position + new Vector3(-1.5f, 0, 0),1f); // } //} private void Update() { if(isMove && headpos!=null) { //float x = transform.position.x - headpos.position.x; //float z = transform.position.z - headpos.position.z; //if (Mathf.Abs(x) > 0.8f || Mathf.Abs(z) > 0.8f) //{ // //transform.position = new Vector3(headpos.position.x + x > 0 ? 0.8f : -0.8f, -0.3f, headpos.position.z + z > 0 ? 0.8f : -0.8f); // transform.eulerAngles = new Vector3(30, headpos.eulerAngles.y, 0); //} //float dis = Vector2.Distance(new Vector2(transform.position.x, transform.position.z), new Vector2(headpos.position.x, headpos.position.z)); //if (dis > 0.8f) //{ // transform.position = new Vector3(headpos.position.x + 0.8f, -0.3f, headpos.position.z + 0.8f); // transform.eulerAngles = new Vector3(30, headpos.eulerAngles.y, 0); //} //Vector3 pos = Vector3.zero; //float x = transform.position.x - headpos.position.x; //float z = transform.position.z - headpos.position.z; //if(x>0.8f) //{ // pos.x = headpos.position.x + 0.8f; //} //else if(x<-0.8f) //{ // pos.x = headpos.position.x - 0.8f; //} //if (z > 0.8f) //{ // pos.z = headpos.position.x + 0.8f; //} //else if (z < -0.8f) //{ // pos.z = headpos.position.x + 0.8f; //} //Debug.Log(pos); //transform.position = pos; //transform.eulerAngles = new Vector3(30, headpos.eulerAngles.y, 0); //float roty = headpos.eulerAngles.y - transform.eulerAngles.y; //Debug.Log(roty); //if(roty >15) //{ // transform.eulerAngles = new Vector3(transform.eulerAngles.x, headpos.eulerAngles.y + 15, transform.eulerAngles.z); //} //else if(roty <-15) //{ // transform.eulerAngles = new Vector3(transform.eulerAngles.x, headpos.eulerAngles.y - 15, transform.eulerAngles.z); //} //roty = headpos.eulerAngles.y - transform.eulerAngles.y; //float x = headpos.position.x + 3 * Mathf.Cos(headpos.eulerAngles.y); //float z = headpos.position.z + 3 * Mathf.Sin(headpos.eulerAngles.y); //transform.position = new Vector3(x, transform.position.y, z); } } public void OpenEditor(Transform target) { this.target = target; isMove = true; transform.eulerAngles = new Vector3(30, target.eulerAngles.y, transform.eulerAngles.z); transform.DOMove(new Vector3(Head.position.x, transform.position.y, Head.position.z), 0.9f); } public void CloseEditor() { this.target = null; isMove = false; transform.position = new Vector3(10000, 0, 0); } public void SettingEditor(Transform headPos) { isMove = !isMove; headpos = headPos; if (isMove) { transform.position = new Vector3(headpos.position.x, -0.3f, headpos.position.z); transform.eulerAngles = new Vector3(30, headpos.eulerAngles.y, 0); } else { transform.position = new Vector3(10000, 0, 0); } } }