Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class Player : MonoBehaviour {
- [SerializeField]
- private float movementSpeed = 0.0f;
- public Rigidbody rb;
- void Start ()
- {
- Physics.gravity = new Vector3 (0, -45F, 0);
- rb = GetComponent<Rigidbody> ();
- }
- void Update ()
- {
- Move ();
- }
- private void Move ()
- {
- if (Input.GetAxis ("Vertical") != 0)
- {
- rb.constraints = RigidbodyConstraints.FreezeRotationY | RigidbodyConstraints.FreezeRotationX;
- float hAxis = Input.GetAxis ("Vertical");
- Vector3 moveDir = new Vector3 (hAxis, 0, 0);
- rb.velocity = moveDir * movementSpeed * Time.deltaTime;
- }
- else if (Input.GetAxis ("Horizontal") != 0)
- {
- rb.constraints = RigidbodyConstraints.FreezeRotationY | RigidbodyConstraints.FreezeRotationZ;
- float hAxis = Input.GetAxis("Horizontal");
- Vector3 moveDir = new Vector3 (0, 0, hAxis);
- rb.velocity = moveDir * movementSpeed * Time.deltaTime;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment