【问题标题】:Unity VR Player camera not moving when running in real deviceUnity VR Player相机在真实设备中运行时不移动
【发布时间】:2017-06-23 11:54:46
【问题描述】:

我是 Unity 的初学者,并遵循 Udemy 教程使用 Unity 学习 VR 并制作名为 Ninja Slash 的游戏。在 Unity 编辑器播放模式 下一切似乎都运行良好,但是当我在 真实设备 中运行我的应用程序时,我的播放器根本不动强>。我不知道这里有什么问题。

这是我的播放器脚本。

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 等。

【问题讨论】:

  • 相机和你的玩家脚本在同一个游戏对象上吗?尝试将相机放置在 Player 的子级上。
  • 播放器本身就是相机

标签: c# unity3d google-vr


【解决方案1】:

我相信你无法在 VR 模式下更改主摄像头的变换。您必须将主摄像机设为另一个对象的子对象(空?!),然后移动该对象。

【讨论】:

  • 我也试过了,但也不是每次都有效。
猜你喜欢
  • 2018-08-19
  • 2018-11-21
  • 1970-01-01
  • 2015-02-07
  • 2015-02-09
  • 1970-01-01
  • 2017-11-20
  • 2020-08-01
  • 1970-01-01
相关资源
最近更新 更多