Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using UnityEngine.UI;
- public class GuyMove : MonoBehaviour
- {
- [SerializeField]
- private float speed = 5f;
- [SerializeField]
- private float jumpSpeed = 10f;
- //переменная, отвечающая за нашу физику
- private Rigidbody rb;
- public Text ScoreTextTime;
- private float scoreTime;
- private Vector3 direction;
- private bool finishGame;
- private void Start()
- {
- rb = GetComponent<Rigidbody>();
- }
- public void ResetPosition()
- {
- transform.position = startPosition;
- }
- private void Update()
- {
- if (isGrounded())
- {
- if (Input.GetKeyDown(KeyCode.Space))
- {
- rb.AddForce(new Vector3(0, jumpSpeed, 0), ForceMode.Impulse);
- }
- }
- }
- private bool isGrounded()
- {
- return Physics.Raycast(transform.position, -Vector3.up, 2 + 0.1f);
- }
- private void FixedUpdate()
- {
- float horizontal = Input.GetAxis("Horizontal");
- float vertical = Input.GetAxis("Vertical");
- direction = transform.TransformDirection(new Vector3(horizontal, 0, vertical));
- rb.MovePosition(transform.position + direction * speed * Time.deltaTime);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement