在代码编辑器MomoDevelop或VS2015中,将以下代码输入,然后按CTRL+S保存代码。
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerController : MonoBehaviour {
private Transform m_Transform;
void Start () {
m_Transform = gameObject.GetComponent();
}
// Update is called once per frame
void Update () {
MoveControl();
}
void MoveControl()
{
if (Input.GetKey(KeyCode.W))
{
m_Transform.Translate(Vector3.forward * 0.1f, Space.Self);
}
if (Input.GetKey(KeyCode.S))
{
m_Transform.Translate(Vector3.back * 0.1f, Space.Self);
}
if (Input.GetKey(KeyCode.A))
{
m_Transform.Translate(Vector3.left * 0.1f, Space.Self);
}
if (Input.GetKey(K