Created
September 13, 2018 15:23
-
-
Save nabesi777/168807235668da12de43a97b8516fe8c to your computer and use it in GitHub Desktop.
PlayerMove [Rigidbody] C#
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections; | |
using System.Collections.Generic; | |
using UnityEngine; | |
public class PlayerMove : MonoBehaviour | |
{ | |
public float speed = 3f; | |
float moveX = 0f; | |
float moveZ = 0f; | |
Rigidbody rb; | |
void Start() | |
{ | |
rb = GetComponent<Rigidbody>(); | |
} | |
void Update() | |
{ | |
moveX = Input.GetAxis("Horizontal") * speed; | |
moveZ = Input.GetAxis("Vertical") * speed; | |
Vector3 direction = new Vector3(moveX, 0, moveZ); | |
} | |
void FixedUpdate() | |
{ | |
rb.velocity = new Vector3(moveX, 0, moveZ); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment