Advertisement
kadyr

Untitled

Oct 12th, 2021
222
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.02 KB | None | 0 0
  1. using System.Collections.Generic;
  2. using UnityEngine;
  3. using UnityEngine.UI;
  4. using UnityEngine.SceneManagement;
  5.  
  6. public class Move : MonoBehaviour
  7. {
  8. private Rigidbody rb; // ��������� Rigidbody
  9. public float speed = 15;
  10. Vector3 direction;
  11. [SerializeField] Vector3 startPosition;
  12. float timer;
  13. [SerializeField] GameObject player;
  14. float speedRotation;
  15. float jumpSpeed;
  16. [SerializeField] Animator Player;
  17. float turnSmoothTime = 0.1f;
  18. float turnSmoothVelocity;
  19. [SerializeField] private Camera camera;
  20. [SerializeField] private float step;
  21.  
  22.  
  23. void Start()
  24. {
  25. startPosition = transform.position;
  26. rb = GetComponent<Rigidbody>(); //������� ��������� � ������� � ����������
  27. }
  28.  
  29. Vector3 MousePosInWorldSpace()
  30. {
  31.  
  32. return Camera.main.ScreenToWorldPoint(Input.mousePosition);
  33.  
  34. }
  35.  
  36. private void Update()
  37. {
  38. CalucateDeltaAngle();
  39.  
  40. Vector3 mouse = Input.mousePosition;
  41. Ray castPoint = Camera.main.ScreenPointToRay(mouse);
  42. RaycastHit hit;
  43. if (Physics.Raycast(castPoint, out hit, Mathf.Infinity))
  44. {
  45. transform.LookAt(new Vector3(hit.point.x,transform.rotation.y, hit.point.z));
  46. }
  47.  
  48. //��������� ��� �� �� ����� (���������� �����)
  49. if (Physics.Raycast(transform.position, -Vector3.up, 1 + 0.1f))
  50. {
  51. //������� �� ������
  52. if (Input.GetKeyDown(KeyCode.Space))
  53. {
  54. rb.AddForce(new Vector3(0, 8, 0), ForceMode.Impulse);
  55. }
  56.  
  57. }
  58. //���� �������� ���� �� �������� ��� ������� �� �����
  59. if (transform.position.y < -10)
  60. {
  61. transform.position = new Vector3(5,5,5);
  62. }
  63.  
  64. if (Input.GetKeyDown(KeyCode.LeftShift))
  65. {
  66. speed = 30;
  67. }
  68. if (Input.GetKeyUp(KeyCode.LeftShift))
  69. {
  70. speed = 15;
  71. }
  72. float horizontal = Input.GetAxis("Horizontal");
  73. float vertical = Input.GetAxis("Vertical");
  74.  
  75.  
  76.  
  77. direction = transform.TransformDirection(horizontal, 0, vertical);
  78. rb.MovePosition(transform.position + speed * direction * Time.deltaTime);
  79.  
  80. timer += Time.deltaTime;
  81. }
  82. private void OnTriggerEnter(Collider collider)
  83. {
  84.  
  85. }
  86.  
  87. private void RotateTowards(float angle)
  88. {
  89. Vector3 euler = transform.eulerAngles;
  90. euler.y = Mathf.Round(angle / step) * step;
  91. transform.eulerAngles = euler;
  92. }
  93.  
  94. private void CalucateDeltaAngle()
  95. {
  96. Vector3 delta = transform.position - Input.mousePosition;
  97. RotateTowards(Quaternion.LookRotation(delta, transform.up).eulerAngles.y);
  98. }
  99. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement