我需要在游戏中移动gvr cam,但在Android应用程序中它不会移动... 我已经尝试过使用此代码:
public class controller : MonoBehaviour {
private bool walking = false;
private Vector3 spawnPoint;
void Start () {
spawnPoint = transform.position;
}
void Update () {
if (walking)
{
transform.position = transform.position + Camera.main.transform.forward * 3 * Time.deltaTime;
}
if (transform.position.y <-10f)
{
transform.position = spawnPoint;
}
Ray ray = Camera.main.ViewportPointToRay(new Vector3(.5f, .5f, 0));
RaycastHit hit;
if (Physics.Raycast (ray, out hit))
{
if (hit.collider.name.Contains("plane"))
{
walking = false;
} else
{
walking = true;
}
}
}
答案 0 :(得分:0)
可能是这样的:
if (hit.collider.name.Contains("plane"))
但在现场你有&#34;飞机&#34;不是&#34;飞机&#34; ;)
尝试使用layers和layerMask而不是通过名称检查。你可以在这里阅读:Unity Manual: Layers