TestPos.cs 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5. public class TestPos : MonoBehaviour
  6. {
  7. [HideInInspector]
  8. public Vector3 startPos = Vector3.zero;
  9. public LineRenderer line1;
  10. public LineRenderer line3;
  11. public Text text;
  12. public LodingPanelManager showObj;
  13. float times = 0;
  14. bool state = true;
  15. /// <summary>
  16. /// 根据Gps值的变化移动物体
  17. /// </summary>
  18. /// <param name="Pos"></param>
  19. public void ObjectMove(Vector3 Pos)
  20. {
  21. // text.text = startPos.ToString();
  22. //text.text = " TestPos One";
  23. if (startPos.x == 0 || startPos.z == 0)
  24. return;
  25. //if (state)
  26. //{
  27. // state = false;
  28. // transform.position = new Vector3(0, -0.08f, 0);
  29. //}
  30. if (times < 0.1f)
  31. return;
  32. else
  33. times = 0;
  34. if (Mathf.Abs(transform.position.x) > 10000 || Mathf.Abs(transform.position.y) > 10000)
  35. transform.position = new Vector3(0, -0.08f, 0);
  36. Vector3 newPos = new Vector3(Pos.z - startPos.z, 0, startPos.x - Pos.x);
  37. text.text = newPos.x.ToString() + " , 0 , " + newPos.z.ToString();
  38. transform.position -= newPos;
  39. //transform.position += new Vector3(0.01f, 0, 0);
  40. // text.text = newPos.ToString();
  41. startPos = Pos;
  42. // transform.position += Pos;
  43. }
  44. private void Update()
  45. {
  46. times += Time.deltaTime;
  47. //if(showObj.state)
  48. //{
  49. // showObj.times += Time.deltaTime;
  50. // if(showObj.times>3f)
  51. // {
  52. // showObj.state = false;
  53. // showObj.ShowGameObj();
  54. // }
  55. //}
  56. // transform.position += new Vector3(0.02f, 0, 0);
  57. ShowLine();
  58. }
  59. private void LateUpdate()
  60. {
  61. }
  62. void ShowLine()
  63. {
  64. line1.gameObject.SetActive(true);
  65. line3.gameObject.SetActive(true);
  66. Debug.Log(123);
  67. line1.SetPosition(0, new Vector3(transform.position.x - 10, -1, transform.position.z));
  68. line1.SetPosition(1, new Vector3(transform.position.x + 10, -1, transform.position.z));
  69. //line2.SetPosition(0).transform.position + new Vector3(0, -20, 0));
  70. //line2.SetPosition(1).transform.position + new Vector3(0, 20, 0));
  71. line3.SetPosition(0, new Vector3(transform.position.x, -1, transform.position.z - 10));
  72. line3.SetPosition(1, new Vector3(transform.position.x, -1, transform.position.z + 10));
  73. //line3.SetPosition(0, transform.position + new Vector3(0, 0, -10));
  74. //line3.SetPosition(1, transform.position + new Vector3(0, 0, 10));
  75. }
  76. }