123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class Scenes5FollowCamera : MonoBehaviour
- {
- public TextMesh textm;
- // Start is called before the first frame update
- void Start()
- {
- }
- float delayTime = 0f;
- float time = 0;
- bool isMove;
- Vector3 v3;
- public float MOVETIME = 0.5f;
- float DEALYTIME = 1f;
- float DISTANCE = 0;
- LeanTweenType leanTween = LeanTweenType.easeOutSine;
- // Update is called once per frame
- float jiaoduA;
- float jiaoduB;
- void checkEul()
- {
- /*
- /* if (isMove)
- {
- time = time + Time.deltaTime;
- if (time > MOVETIME*2)
- {
- time = 0;
- isMove = false;
- }
- }*/
- jiaoduA = this.transform.eulerAngles.y;
- jiaoduB = SvrManager.Instance.head.transform.eulerAngles.y;
- float ty = jiaoduA;
- float hty = jiaoduB;
- bool check = false;
- bool checkzf = false;
- float jiaodu;
- Vector3 ppv3 = this.transform.position;
- Vector3 hpv3 = SvrManager.Instance.head.transform.position;
- float distancex = Mathf.Abs(ppv3.x - hpv3.x);
- float dis = DISTANCE / (distancex + 1);
- if (Mathf.Abs(ty - hty) < 180 && Mathf.Abs(ty - hty) > dis)
- {
- jiaodu = Mathf.Abs(ty - hty);
- check = true;
- if (ty > hty)
- {
- checkzf = true;
- }
- else
- {
- checkzf = false;
- }
- }
- else if (Mathf.Abs(ty - hty) > 180 && (360 - Mathf.Abs(ty - hty)) > dis)
- {
- jiaodu = (360 - Mathf.Abs(ty - hty));
- check = true;
- if (ty > hty)
- {
- checkzf = false;
- }
- else
- {
- checkzf = true;
- }
- }
- else
- {
- if (Mathf.Abs(ty - hty) < 180)
- {
- jiaodu = Mathf.Abs(ty - hty);
- }
- else
- {
- jiaodu = (360 - Mathf.Abs(ty - hty));
- }
- }
- // GetAngle(SvrManager.Instance.head, this.transform);
- // this.transform.position = SvrManager.Instance.head.transform.position;
- if (check && !isMove)
- {
- // delayTime = delayTime + Time.deltaTime;
- // if (delayTime > DEALYTIME)
- // {
- // MovePos();
- if (checkzf)
- {
- // Debug.Log("角度差值===》" + jiaodu);
- v3 = new Vector3(0, SvrManager.Instance.head.transform.eulerAngles.y + dis, 0);
- }
- else
- {
- // Debug.Log("角度差值===》" + -jiaodu);
- v3 = new Vector3(0, SvrManager.Instance.head.transform.eulerAngles.y - dis, 0);
- }
- // float a= Mathf.Lerp(this.transform.eulerAngles.y, v3.y, Time.time);
- this.transform.rotation = Quaternion.Lerp(this.transform.rotation, Quaternion.Euler(v3), 0.1f);
- // this.transform.Rotate(0,a,0);
- // LTDescr lt = LeanTween.rotate(this.gameObject, v3, ((jiaodu - dis) / 150f));
- // Invoke("isEndRotate", 0.3f);
- // Debug.Log((this.transform.eulerAngles.y-v3.y));
- // this.transform.eulerAngles = v3;
- // this.transform.eulerAngles = v3;
- // MoveEul();
- // }
- // isMove = true;
- }
- else
- {
- delayTime = 0;
- }
- }
- void isEndRotate()
- {
- isMove = false;
- }
- bool ispMove;
- float pdelayTime = 0f;
- float ptime = 0;
- bool pisMove;
- Vector3 pv3;
- float PMOVETIME = 0.5f;
- float PDEALYTIME = 0.5f;
- float PDISTANCEX = 0.2f;
- float PDISTANCEY = 0.4f;
- float PDISTANCEYY = 0.1f;
- float PDISTANCEZ = 0.2f;
- float PDISTANCEZZ = 0.2f;
- LeanTweenType pleanTween = LeanTweenType.easeOutSine;
- float timeD = 0.1f;
- void checkPos()
- {
- Vector3 ppv3 = this.transform.position;
- Vector3 hpv3 = SvrManager.Instance.head.transform.position;
- float distancey = ppv3.y - hpv3.y;
- float distancex = Mathf.Abs(ppv3.x - hpv3.x);
- float distancez = ppv3.z - hpv3.z;
- if (distancey > PDISTANCEY)
- {
- // Debug.Log("555555555555");
- pv3 = new Vector3(ppv3.x, ppv3.y - (distancey - PDISTANCEY), ppv3.z);
- // LeanTween.move(this.gameObject, pv3, PMOVETIME).setEase(pleanTween);
- // this.transform.position = pv3;
- this.transform.position = Vector3.Lerp(this.transform.position, pv3, timeD);
- // MoveEul();
- // MovePos();
- }
- else if (hpv3.y > ppv3.y && Mathf.Abs(distancey) > PDISTANCEYY)
- {
- // Debug.Log("4444444");
- pv3 = new Vector3(ppv3.x, ppv3.y + (Mathf.Abs(distancey) - PDISTANCEYY), ppv3.z);
- this.transform.position = Vector3.Lerp(this.transform.position, pv3, timeD);
- // MoveEul();
- }
- ppv3 = this.transform.position;
- hpv3 = SvrManager.Instance.head.transform.position;
- distancey = ppv3.y - hpv3.y;
- distancex = Mathf.Abs(ppv3.x - hpv3.x);
- distancez = ppv3.z - hpv3.z;
- if (distancex > PDISTANCEX)
- {
- // Debug.Log("333333");
- if (ppv3.x > hpv3.x)
- pv3 = new Vector3(ppv3.x - (distancex - PDISTANCEX), ppv3.y, ppv3.z);
- else
- pv3 = new Vector3(ppv3.x + (distancex - PDISTANCEX), ppv3.y, ppv3.z);
- this.transform.position = Vector3.Lerp(this.transform.position, pv3, timeD);
- // LeanTween.move(this.gameObject, pv3, PMOVETIME).setEase(pleanTween);
- // this.transform.position = pv3;
- // MovePos();
- // MoveEul();
- }
- ppv3 = this.transform.position;
- hpv3 = SvrManager.Instance.head.transform.position;
- distancey = ppv3.y - hpv3.y;
- distancex = Mathf.Abs(ppv3.x - hpv3.x);
- distancez = ppv3.z - hpv3.z;
- if (distancez > PDISTANCEZ)
- {
- // Debug.Log("111111111");
- pv3 = new Vector3(ppv3.x, ppv3.y, ppv3.z - (distancez - PDISTANCEZ));
- this.transform.position = Vector3.Lerp(this.transform.position, pv3, timeD);
- // LeanTween.move(this.gameObject, pv3, PMOVETIME).setEase(pleanTween);
- // this.transform.position = pv3;
- // MovePos();
- // MoveEul();
- }
- else if (hpv3.z > ppv3.z && Mathf.Abs(distancez) > PDISTANCEZZ)
- {
- // Debug.Log("22222222");
- pv3 = new Vector3(ppv3.x, ppv3.y, ppv3.z + (Mathf.Abs(distancez) - PDISTANCEZZ));
- this.transform.position = Vector3.Lerp(this.transform.position, pv3, timeD);
- // this.transform.position = pv3;
- // MoveEul();
- }
- }
- void Update()
- {
- checkEul();
- checkPos();
- //pv3 = new Vector3(SvrManager.Instance.head.transform.position.x, 0, SvrManager.Instance.head.transform.position.z);
- // LeanTween.move(this.gameObject, pv3, PMOVETIME).setEase(pleanTween);
- // this.transform.position = pv3;
- }
- void MovePos()
- {
- // pdelayTime = 0;
- pv3 = new Vector3(SvrManager.Instance.head.transform.position.x, 0, SvrManager.Instance.head.transform.position.z);
- LeanTween.move(this.gameObject, pv3, PMOVETIME).setEase(pleanTween);
- // this.transform.position = pv3;
- // pisMove = true;
- }
- void MoveEul()
- {
- if (!isMove)
- {
- // MovePos();
- delayTime = 0;
- v3 = new Vector3(0, SvrManager.Instance.head.transform.eulerAngles.y, 0);
- // LeanTween.rotateY(this.gameObject, v3.y, MOVETIME).setEase(leanTween);
- // isMove = true;
- }
- }
- }
|