Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using System.Security;
- using UnityEngine;
- public class GuyMove : MonoBehaviour
- {
- private Rigidbody rb; //получаем физику
- [SerializeField]
- private float speed = 5f;
- private Vector3 direction;
- private Vector3 startPosition;
- void Start()
- {
- startPosition = transform.position;
- rb = GetComponent<Rigidbody>();
- }
- void Update()
- {
- if (Input.GetKeyDown(KeyCode.Space))
- {
- rb.AddForce(transform.up * 10f, ForceMode.Impulse);
- }
- if (transform.position.y < -10)
- transform.position = startPosition;
- }
- private void FixedUpdate()
- {
- float horizontal = Input.GetAxis("Horizontal");
- float vertical = Input.GetAxis("Vertical");
- direction = transform.TransformDirection(horizontal, 0, vertical);
- rb.MovePosition(transform.position + direction*speed*Time.fixedDeltaTime);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement