我的播放器无法移入我的gvr应用

时间:2017-06-22 20:42:42

标签: android unity3d google-cardboard

我需要在游戏中移动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;
        }
    }

}

In the image linked here there is my plane

1 个答案:

答案 0 :(得分:0)

可能是这样的:

if (hit.collider.name.Contains("plane"))

但在现场你有&#34;飞机&#34;不是&#34;飞机&#34; ;)

尝试使用layers和layerMask而不是通过名称检查。你可以在这里阅读:Unity Manual: Layers