我正在关注此入门教程,内容涉及如何开始使用Unity为Oculus构建游戏:https://developer.oculus.com/documentation/unity/latest/concepts/unity-tutorial/
我添加了地板和四堵墙。我还添加了Sphere Player对象。
最后,我已将PlayerController脚本添加到播放器对象中。
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerController : MonoBehaviour
{
public int speed = 0;
// Start is called before the first frame update
void Start() {}
// Update is called once per frame
void Update()
{
// get input data from keyboard or controller
float moveHorizontal = Input.GetAxis("Horizontal");
float moveVertical = Input.GetAxis("Vertical");
// update player position based on input
Vector3 position = transform.position;
position.x += moveHorizontal * speed * Time.deltaTime;
position.y += moveVertical * speed * Time.deltaTime;
transform.position = position;
}
}
本教程说:
这时,如果您通过按“播放”按钮在“游戏视图”中预览游戏,您会发现可以使用箭头键或键盘上的W-A-S-D控制玩家。
但是,按下播放器后,我发现无法控制播放器。光标键或W-A-S-D都不起作用。
我错过了任何明显的事情吗?我需要手动进行一些其他设置吗?
答案 0 :(得分:-1)
默认情况下,速度值设置为零,请确保在检查器中而不是在“播放”模式下编辑该值,因为它不会保存在那里。
答案 1 :(得分:-1)
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerController : MonoBehaviour {
// public int speed = 0; // The zero (0) is the absorbing element 0*x=0
public int speed = 1; // Replace with a value other than zero (0)
// Start is called before the first frame update
void Start() {}
// Update is called once per frame
void Update() {
// get input data from keyboard or controller
float moveHorizontal = Input.GetAxis("Horizontal");
float moveVertical = Input.GetAxis("Vertical");
// update player position based on input
Vector3 position = transform.position;
position.x += moveHorizontal * speed * Time.deltaTime;
position.y += moveVertical * speed * Time.deltaTime;
transform.position = position;
}
}