簡體   English   中英

在真實設備中運行時,Unity VR Player相機無法移動

[英]Unity VR Player camera not moving when running in real device

我是Unity的初學者,並按照Udemy教程學習如何使用Unity學習VR並制作一個名為Ninja Slash的游戲。 Unity Editor的Play模式下,一切似乎都可以正常工作,但是當我在真實的設備上運行應用程序時, 播放器根本不會移動 我不知道這是什么問題。

這是我的播放器腳本。

public class Player : MonoBehaviour {

public GameObject sword;
public float speed = 4.5f;
public float walkingAmplitude = 0.25f;
public float walkingFrequency = 2.0f;
public float swordRange = 1.75f;
public float swordCooldown = 0.25f;

public bool isDead = false;
public bool hasCrossedFinishLine = false;

private float cooldownTimer;
private Vector3 swordTargetPosition;

// Use this for initialization
void Start () {
    swordTargetPosition = sword.transform.localPosition;
}

// Update is called once per frame
void Update () {
    if (isDead) {
        return;
    }

    transform.position += Vector3.forward * speed * Time.deltaTime;
    transform.position = new Vector3(
        transform.position.x,
        1.7f + Mathf.Cos(transform.position.z * walkingFrequency) * walkingAmplitude,
        transform.position.z
    );

    cooldownTimer -= Time.deltaTime;

    if (GvrViewer.Instance.Triggered ) {
        RaycastHit hit;

        if (cooldownTimer <= 0f && Physics.Raycast(transform.position, transform.forward, out hit)) {
            cooldownTimer = swordCooldown;

            if (hit.transform.GetComponent<Enemy> () != null && hit.transform.position.z - this.transform.position.z < swordRange) {
                Destroy (hit.transform.gameObject);
                swordTargetPosition = new Vector3 (-swordTargetPosition.x, swordTargetPosition.y, swordTargetPosition.z);
            }
        }
    }

    sword.transform.localPosition = Vector3.Lerp (sword.transform.localPosition, swordTargetPosition, Time.deltaTime * 15f);
}

void OnTriggerEnter (Collider collider) {
    if (collider.GetComponent<Enemy> () != null) {
        isDead = true;
    } else if (collider.tag == "FinishLine") {
        hasCrossedFinishLine = true;
    }
}}

這是層次結構視圖的屏幕截圖。

在此處輸入圖片說明

我嘗試使用不同版本的gvr sdk unity軟件包,但每次都得到相同的結果,並且我還嘗試運行它,例如htc,samsung等不同的設備。

我相信您無法在VR模式下更改主相機的變換。 您必須將主相機設為另一個對象的子對象(空?!),然后移動該對象。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM