Scenes5FollowCamera.cs 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. public class Scenes5FollowCamera : MonoBehaviour
  5. {
  6. public TextMesh textm;
  7. // Start is called before the first frame update
  8. void Start()
  9. {
  10. }
  11. float delayTime = 0f;
  12. float time = 0;
  13. bool isMove;
  14. Vector3 v3;
  15. public float MOVETIME = 0.5f;
  16. float DEALYTIME = 1f;
  17. float DISTANCE = 0;
  18. LeanTweenType leanTween = LeanTweenType.easeOutSine;
  19. // Update is called once per frame
  20. float jiaoduA;
  21. float jiaoduB;
  22. void checkEul()
  23. {
  24. /*
  25. /* if (isMove)
  26. {
  27. time = time + Time.deltaTime;
  28. if (time > MOVETIME*2)
  29. {
  30. time = 0;
  31. isMove = false;
  32. }
  33. }*/
  34. jiaoduA = this.transform.eulerAngles.y;
  35. jiaoduB = SvrManager.Instance.head.transform.eulerAngles.y;
  36. float ty = jiaoduA;
  37. float hty = jiaoduB;
  38. bool check = false;
  39. bool checkzf = false;
  40. float jiaodu;
  41. Vector3 ppv3 = this.transform.position;
  42. Vector3 hpv3 = SvrManager.Instance.head.transform.position;
  43. float distancex = Mathf.Abs(ppv3.x - hpv3.x);
  44. float dis = DISTANCE / (distancex + 1);
  45. if (Mathf.Abs(ty - hty) < 180 && Mathf.Abs(ty - hty) > dis)
  46. {
  47. jiaodu = Mathf.Abs(ty - hty);
  48. check = true;
  49. if (ty > hty)
  50. {
  51. checkzf = true;
  52. }
  53. else
  54. {
  55. checkzf = false;
  56. }
  57. }
  58. else if (Mathf.Abs(ty - hty) > 180 && (360 - Mathf.Abs(ty - hty)) > dis)
  59. {
  60. jiaodu = (360 - Mathf.Abs(ty - hty));
  61. check = true;
  62. if (ty > hty)
  63. {
  64. checkzf = false;
  65. }
  66. else
  67. {
  68. checkzf = true;
  69. }
  70. }
  71. else
  72. {
  73. if (Mathf.Abs(ty - hty) < 180)
  74. {
  75. jiaodu = Mathf.Abs(ty - hty);
  76. }
  77. else
  78. {
  79. jiaodu = (360 - Mathf.Abs(ty - hty));
  80. }
  81. }
  82. // GetAngle(SvrManager.Instance.head, this.transform);
  83. // this.transform.position = SvrManager.Instance.head.transform.position;
  84. if (check && !isMove)
  85. {
  86. // delayTime = delayTime + Time.deltaTime;
  87. // if (delayTime > DEALYTIME)
  88. // {
  89. // MovePos();
  90. if (checkzf)
  91. {
  92. // Debug.Log("角度差值===》" + jiaodu);
  93. v3 = new Vector3(0, SvrManager.Instance.head.transform.eulerAngles.y + dis, 0);
  94. }
  95. else
  96. {
  97. // Debug.Log("角度差值===》" + -jiaodu);
  98. v3 = new Vector3(0, SvrManager.Instance.head.transform.eulerAngles.y - dis, 0);
  99. }
  100. // float a= Mathf.Lerp(this.transform.eulerAngles.y, v3.y, Time.time);
  101. this.transform.rotation = Quaternion.Lerp(this.transform.rotation, Quaternion.Euler(v3), 0.1f);
  102. // this.transform.Rotate(0,a,0);
  103. // LTDescr lt = LeanTween.rotate(this.gameObject, v3, ((jiaodu - dis) / 150f));
  104. // Invoke("isEndRotate", 0.3f);
  105. // Debug.Log((this.transform.eulerAngles.y-v3.y));
  106. // this.transform.eulerAngles = v3;
  107. // this.transform.eulerAngles = v3;
  108. // MoveEul();
  109. // }
  110. // isMove = true;
  111. }
  112. else
  113. {
  114. delayTime = 0;
  115. }
  116. }
  117. void isEndRotate()
  118. {
  119. isMove = false;
  120. }
  121. bool ispMove;
  122. float pdelayTime = 0f;
  123. float ptime = 0;
  124. bool pisMove;
  125. Vector3 pv3;
  126. float PMOVETIME = 0.5f;
  127. float PDEALYTIME = 0.5f;
  128. float PDISTANCEX = 0.2f;
  129. float PDISTANCEY = 0.4f;
  130. float PDISTANCEYY = 0.1f;
  131. float PDISTANCEZ = 0.2f;
  132. float PDISTANCEZZ = 0.2f;
  133. LeanTweenType pleanTween = LeanTweenType.easeOutSine;
  134. float timeD = 0.1f;
  135. void checkPos()
  136. {
  137. Vector3 ppv3 = this.transform.position;
  138. Vector3 hpv3 = SvrManager.Instance.head.transform.position;
  139. float distancey = ppv3.y - hpv3.y;
  140. float distancex = Mathf.Abs(ppv3.x - hpv3.x);
  141. float distancez = ppv3.z - hpv3.z;
  142. if (distancey > PDISTANCEY)
  143. {
  144. // Debug.Log("555555555555");
  145. pv3 = new Vector3(ppv3.x, ppv3.y - (distancey - PDISTANCEY), ppv3.z);
  146. // LeanTween.move(this.gameObject, pv3, PMOVETIME).setEase(pleanTween);
  147. // this.transform.position = pv3;
  148. this.transform.position = Vector3.Lerp(this.transform.position, pv3, timeD);
  149. // MoveEul();
  150. // MovePos();
  151. }
  152. else if (hpv3.y > ppv3.y && Mathf.Abs(distancey) > PDISTANCEYY)
  153. {
  154. // Debug.Log("4444444");
  155. pv3 = new Vector3(ppv3.x, ppv3.y + (Mathf.Abs(distancey) - PDISTANCEYY), ppv3.z);
  156. this.transform.position = Vector3.Lerp(this.transform.position, pv3, timeD);
  157. // MoveEul();
  158. }
  159. ppv3 = this.transform.position;
  160. hpv3 = SvrManager.Instance.head.transform.position;
  161. distancey = ppv3.y - hpv3.y;
  162. distancex = Mathf.Abs(ppv3.x - hpv3.x);
  163. distancez = ppv3.z - hpv3.z;
  164. if (distancex > PDISTANCEX)
  165. {
  166. // Debug.Log("333333");
  167. if (ppv3.x > hpv3.x)
  168. pv3 = new Vector3(ppv3.x - (distancex - PDISTANCEX), ppv3.y, ppv3.z);
  169. else
  170. pv3 = new Vector3(ppv3.x + (distancex - PDISTANCEX), ppv3.y, ppv3.z);
  171. this.transform.position = Vector3.Lerp(this.transform.position, pv3, timeD);
  172. // LeanTween.move(this.gameObject, pv3, PMOVETIME).setEase(pleanTween);
  173. // this.transform.position = pv3;
  174. // MovePos();
  175. // MoveEul();
  176. }
  177. ppv3 = this.transform.position;
  178. hpv3 = SvrManager.Instance.head.transform.position;
  179. distancey = ppv3.y - hpv3.y;
  180. distancex = Mathf.Abs(ppv3.x - hpv3.x);
  181. distancez = ppv3.z - hpv3.z;
  182. if (distancez > PDISTANCEZ)
  183. {
  184. // Debug.Log("111111111");
  185. pv3 = new Vector3(ppv3.x, ppv3.y, ppv3.z - (distancez - PDISTANCEZ));
  186. this.transform.position = Vector3.Lerp(this.transform.position, pv3, timeD);
  187. // LeanTween.move(this.gameObject, pv3, PMOVETIME).setEase(pleanTween);
  188. // this.transform.position = pv3;
  189. // MovePos();
  190. // MoveEul();
  191. }
  192. else if (hpv3.z > ppv3.z && Mathf.Abs(distancez) > PDISTANCEZZ)
  193. {
  194. // Debug.Log("22222222");
  195. pv3 = new Vector3(ppv3.x, ppv3.y, ppv3.z + (Mathf.Abs(distancez) - PDISTANCEZZ));
  196. this.transform.position = Vector3.Lerp(this.transform.position, pv3, timeD);
  197. // this.transform.position = pv3;
  198. // MoveEul();
  199. }
  200. }
  201. void Update()
  202. {
  203. checkEul();
  204. checkPos();
  205. //pv3 = new Vector3(SvrManager.Instance.head.transform.position.x, 0, SvrManager.Instance.head.transform.position.z);
  206. // LeanTween.move(this.gameObject, pv3, PMOVETIME).setEase(pleanTween);
  207. // this.transform.position = pv3;
  208. }
  209. void MovePos()
  210. {
  211. // pdelayTime = 0;
  212. pv3 = new Vector3(SvrManager.Instance.head.transform.position.x, 0, SvrManager.Instance.head.transform.position.z);
  213. LeanTween.move(this.gameObject, pv3, PMOVETIME).setEase(pleanTween);
  214. // this.transform.position = pv3;
  215. // pisMove = true;
  216. }
  217. void MoveEul()
  218. {
  219. if (!isMove)
  220. {
  221. // MovePos();
  222. delayTime = 0;
  223. v3 = new Vector3(0, SvrManager.Instance.head.transform.eulerAngles.y, 0);
  224. // LeanTween.rotateY(this.gameObject, v3.y, MOVETIME).setEase(leanTween);
  225. // isMove = true;
  226. }
  227. }
  228. }