|
楼主 |
发表于 2014-10-3 09:36
|
显示全部楼层
using UnityEngine;
using System.Collections;
public class Player : MonoBehaviour {
public int m_movSpeed=2;
Transform m_transform;
CharacterController m_ch;
// Use this for initialization
void Start () {
//获取组件
m_transform = this.transform;
m_ch = this.GetComponent<CharacterController> ();
}
// Update is called once per frame
void Update () {
Control ();
}
void Control(){
float xm=0, ym=0, zm=0;
if(Input.GetKey(KeyCode.W)){
zm+=m_movSpeed*Time.deltaTime;
}
if(Input.GetKey(KeyCode.A)){
xm-=m_movSpeed*Time.deltaTime;
}
if(Input.GetKey(KeyCode.S)){
zm-=m_movSpeed*Time.deltaTime;
}
if(Input.GetKey(KeyCode.D)){
xm+=m_movSpeed*Time.deltaTime;
}
m_ch.Move(m_transform.TransformDirection(new Vector3(xm,ym,zm)));
}
}
|
|