Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- public class PlayerController : MonoBehaviour
- {
- private Rigidbody rb;
- public float speed = 1.0f;
- void Start()
- {
- rb = GetComponent<Rigidbody>();
- }
- void FixedUpdate()
- {
- float moveHorizontal = Input.GetAxis("Horizontal");
- float moveVertical = Input.GetAxis("Vertical");
- Vector3 movement = new Vector3(moveHorizontal, 0.0f, moveVertical);
- rb.AddForce(movement * speed);
- if (Input.GetKeyDown(KeyCode.Space))
- {
- speed = 0;
- rb.velocity = Vector3.zero;
- rb.transform.position = new Vector3(0, 0.5f, 0);
- rb.constraints = RigidbodyConstraints.FreezeAll;
- speed = 1.0f;
- }
- if (moveHorizontal != 0 || moveVertical != 0)
- {
- rb.constraints = RigidbodyConstraints.None;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment