Szkaplerny

RaB

Apr 8th, 2016
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.91 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class PlayerController : MonoBehaviour
  5. {
  6.  
  7.     private Rigidbody rb;
  8.     public float speed = 1.0f;
  9.  
  10.     void Start()
  11.     {
  12.         rb = GetComponent<Rigidbody>();
  13.     }
  14.  
  15.     void FixedUpdate()
  16.     {
  17.         float moveHorizontal = Input.GetAxis("Horizontal");
  18.         float moveVertical = Input.GetAxis("Vertical");
  19.  
  20.         Vector3 movement = new Vector3(moveHorizontal, 0.0f, moveVertical);
  21.  
  22.         rb.AddForce(movement * speed);
  23.  
  24.         if (Input.GetKeyDown(KeyCode.Space))
  25.         {
  26.             speed = 0;
  27.             rb.velocity = Vector3.zero;
  28.             rb.transform.position = new Vector3(0, 0.5f, 0);
  29.             rb.constraints = RigidbodyConstraints.FreezeAll;
  30.             speed = 1.0f;
  31.         }
  32.         if (moveHorizontal != 0 || moveVertical != 0)
  33.         {
  34.             rb.constraints = RigidbodyConstraints.None;
  35.         }
  36.     }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment