Created
December 18, 2017 06:52
-
-
Save jiankaiwang/8f3c0ccbce4c749f55f23489a309db41 to your computer and use it in GitHub Desktop.
The script provides you with basic operations of first personal control on Unity.
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
/* | |
* author : jiankaiwang | |
* description : The script provides you with basic operations of first personal control. | |
* platform : Unity | |
* date : 2017/12 | |
*/ | |
using System.Collections; | |
using System.Collections.Generic; | |
using UnityEngine; | |
public class CharacterController : MonoBehaviour { | |
public float speed = 10.0f; | |
private float translation; | |
private float straffe; | |
// Use this for initialization | |
void Start () { | |
// turn off the cursor | |
Cursor.lockState = CursorLockMode.Locked; | |
} | |
// Update is called once per frame | |
void Update () { | |
// Input.GetAxis() is used to get the user's input | |
// You can furthor set it on Unity. (Edit, Project Settings, Input) | |
translation = Input.GetAxis("Vertical") * speed * Time.deltaTime; | |
straffe = Input.GetAxis("Horizontal") * speed * Time.deltaTime; | |
transform.Translate(straffe, 0, translation); | |
if (Input.GetKeyDown("escape")) { | |
// turn on the cursor | |
Cursor.lockState = CursorLockMode.None; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment