Advertisement
Guest User

Untitled

a guest
Feb 26th, 2020
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.24 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class Player_Moving_Controller : MonoBehaviour
  6. {
  7.  
  8. private GameObject BigCircle; //Большой кружок дмойстика
  9. private GameObject CenterCircle; //Маленький кружок дмойстика
  10. private GameObject SideOfMoving; //та херня, которая светится в сторону ходьбы
  11.  
  12. private bool touchStart = false;
  13. private Vector2 StartPoint;
  14. private Vector2 EndPoint;
  15.  
  16. private Vector3 StartPosOfSideOfMoving;
  17. private float StartAngleOfSideOfPosition;
  18.  
  19.  
  20.  
  21. private void Start()
  22. {
  23. BigCircle = GameObject.Find("Big_Circle_");
  24. CenterCircle = GameObject.Find("Center_Circle");
  25. SideOfMoving = GameObject.Find("Side_Of_Moving");
  26. StartPosOfSideOfMoving = SideOfMoving.transform.position;
  27. StartAngleOfSideOfPosition = SideOfMoving.transform.rotation.z;
  28. }
  29. void Update()
  30. {
  31. CalculatingMoveAndroid();
  32. }
  33. private void FixedUpdate()
  34. {
  35. PlayerMoving();
  36. }
  37.  
  38. private void CalculatingMoveAndroid()
  39. {
  40. if(Input.GetMouseButtonDown(0))
  41. {
  42. StartPoint = Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, Camera.main.transform.position.z)); //calc point from worldSpace
  43. BigCircle.transform.position = StartPoint;
  44. CenterCircle.transform.position = StartPoint;
  45. }
  46. if(Input.GetMouseButton(0))
  47. {
  48. touchStart = true;
  49. EndPoint = Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, Camera.main.transform.position.z)); //calc point from worldSpace
  50. }
  51. else
  52. {
  53. touchStart = false;
  54. }
  55.  
  56. }
  57. private void PlayerMoving()
  58. {
  59.  
  60. if (touchStart)
  61. {
  62. Vector3 offset = EndPoint - StartPoint;
  63. Vector2 direction = Vector2.ClampMagnitude(offset, 0.25f);
  64.  
  65. CenterCircle.transform.position = new Vector2(StartPoint.x + direction.x, StartPoint.y + direction.y);
  66. direction.Normalize();
  67. if (offset.magnitude <= 0.05f)
  68. {
  69. SideOfMoving.transform.position = new Vector2(BigCircle.transform.position.x, BigCircle.transform.position.y + 0.32f);
  70. }
  71. else
  72. {
  73. SideOfMoving.transform.position = new Vector2(StartPoint.x + direction.x, StartPoint.y + direction.y);
  74. if (SideOfMoving.transform.hasChanged)
  75. {
  76. SideOfMoving.transform.Rotate(0.0f, 0.0f, Mathf.Atan2(direction.y, direction.x) * Mathf.Rad2Deg);
  77. SideOfMoving.transform.hasChanged = false;
  78. }
  79.  
  80. }
  81.  
  82. }
  83. else
  84. {
  85. SideOfMoving.transform.SetPositionAndRotation(StartPosOfSideOfMoving,Quaternion.AngleAxis(StartAngleOfSideOfPosition, BigCircle.transform.position));
  86. BigCircle.transform.localPosition = new Vector2(0, -175);
  87. CenterCircle.transform.localPosition = new Vector2(0, 0);
  88. }
  89. }
  90.  
  91.  
  92. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement