Last active
August 29, 2015 14:06
-
-
Save eanakashima/48d4438f52ce98e29525 to your computer and use it in GitHub Desktop.
wwcode game-making class 1 c#
This file contains 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 UnityEngine; | |
using System.Collections; | |
public class ControlMovement : MonoBehaviour { | |
public float speed; | |
public float gravity; | |
public CharacterController controller; | |
Vector3 moveDirection = Vector3.zero; | |
// Use this for initialization | |
void Start () { | |
} | |
// Update is called once per frame | |
void Update () { | |
if (controller.isGrounded) { | |
// calculate move direction from input | |
moveDirection = new Vector3(Input.GetAxis("Horizontal") * speed, 0, 0); | |
// transform move direction from local to world space | |
moveDirection = transform.TransformDirection(moveDirection); | |
} | |
// apply gravity | |
moveDirection.y -= gravity * Time.deltaTime; | |
// move character | |
controller.Move (moveDirection * Time.deltaTime); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment