Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.UI;
- using UnityEngine.SceneManagement;
- public class Move : MonoBehaviour
- {
- private Rigidbody rb; // ��������� Rigidbody
- public float speed = 15;
- Vector3 direction;
- [SerializeField] Vector3 startPosition;
- float timer;
- [SerializeField] GameObject player;
- float speedRotation;
- float jumpSpeed;
- [SerializeField] Animator Player;
- float turnSmoothTime = 0.1f;
- float turnSmoothVelocity;
- [SerializeField] private Camera camera;
- [SerializeField] private float step;
- void Start()
- {
- startPosition = transform.position;
- rb = GetComponent<Rigidbody>(); //������� ��������� � ������� � ����������
- }
- Vector3 MousePosInWorldSpace()
- {
- return Camera.main.ScreenToWorldPoint(Input.mousePosition);
- }
- private void Update()
- {
- CalucateDeltaAngle();
- Vector3 mouse = Input.mousePosition;
- Ray castPoint = Camera.main.ScreenPointToRay(mouse);
- RaycastHit hit;
- if (Physics.Raycast(castPoint, out hit, Mathf.Infinity))
- {
- transform.LookAt(new Vector3(hit.point.x,transform.rotation.y, hit.point.z));
- }
- //��������� ��� �� �� ����� (���������� �����)
- if (Physics.Raycast(transform.position, -Vector3.up, 1 + 0.1f))
- {
- //������� �� ������
- if (Input.GetKeyDown(KeyCode.Space))
- {
- rb.AddForce(new Vector3(0, 8, 0), ForceMode.Impulse);
- }
- }
- //���� �������� ���� �� �������� ��� ������� �� �����
- if (transform.position.y < -10)
- {
- transform.position = new Vector3(5,5,5);
- }
- if (Input.GetKeyDown(KeyCode.LeftShift))
- {
- speed = 30;
- }
- if (Input.GetKeyUp(KeyCode.LeftShift))
- {
- speed = 15;
- }
- float horizontal = Input.GetAxis("Horizontal");
- float vertical = Input.GetAxis("Vertical");
- direction = transform.TransformDirection(horizontal, 0, vertical);
- rb.MovePosition(transform.position + speed * direction * Time.deltaTime);
- timer += Time.deltaTime;
- }
- private void OnTriggerEnter(Collider collider)
- {
- }
- private void RotateTowards(float angle)
- {
- Vector3 euler = transform.eulerAngles;
- euler.y = Mathf.Round(angle / step) * step;
- transform.eulerAngles = euler;
- }
- private void CalucateDeltaAngle()
- {
- Vector3 delta = transform.position - Input.mousePosition;
- RotateTowards(Quaternion.LookRotation(delta, transform.up).eulerAngles.y);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement