Advertisement
kadyr

Untitled

Sep 18th, 2021
856
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.03 KB | None | 0 0
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.Security;
  5. using UnityEngine;
  6.  
  7. public class GuyMove : MonoBehaviour
  8. {
  9.     private Rigidbody rb; //получаем физику
  10.  
  11.     [SerializeField]
  12.     private float speed = 5f;
  13.  
  14.     private Vector3 direction;
  15.     private Vector3 startPosition;
  16.    
  17.     void Start()
  18.     {
  19.         startPosition = transform.position;
  20.         rb = GetComponent<Rigidbody>();
  21.     }
  22.  
  23.     void Update()
  24.     {
  25.         if (Input.GetKeyDown(KeyCode.Space))
  26.         {
  27.             rb.AddForce(transform.up * 10f, ForceMode.Impulse);
  28.         }
  29.  
  30.         if (transform.position.y < -10)
  31.             transform.position = startPosition;
  32.     }
  33.  
  34.     private void FixedUpdate()
  35.     {
  36.         float horizontal = Input.GetAxis("Horizontal");
  37.         float vertical = Input.GetAxis("Vertical");
  38.         direction = transform.TransformDirection(horizontal, 0, vertical);
  39.         rb.MovePosition(transform.position + direction*speed*Time.fixedDeltaTime);
  40.     }
  41. }
  42.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement