First Person Controller(第一人稱角色控制器)
包含
1. 按下play鍵
,操控a,w,s,d,左,前,後,右
3.程式
using UnityEngine;
using System.Collections;
public class Player : MonoBehaviour {
public GameObject obj_Player;
// Use this for
initialization
void Start () {
}
// Update is called once per
frame
void Update ()
{
obj_Player =
GameObject.Find("Sphere");
if (Input.GetKeyDown
(KeyCode.A)) {
obj_Player.transform.position
+= new Vector3 (-0.1f, 0, 0);
} else if
(Input.GetKeyDown (KeyCode.D)) {
obj_Player.transform.position
+= new Vector3 (0.1f, 0, 0);
} else if
(Input.GetKeyDown (KeyCode.W)) {
obj_Player.transform.position
+= new Vector3 (0, 0, 0.1f);
} else if
(Input.GetKeyDown (KeyCode.S)) {
obj_Player.transform.position
+= new Vector3 (0, 0, -0.1f);
}
}
}
執行前
執行後