使用第一人称控制器脚本在纸板中前进

Moving forward in cardboard using first person controller script

如何在google纸板中添加第一人称控制器,使其连续向前移动? 我知道这是个愚蠢的问题,但由于我是新手,实际上只做了几个小时的简单纸板游戏 ago.I 我不知道如何将第一人称控制器脚本添加到我的 google 纸板游戏中?

这是来自 github 的 AutoWalk.cs 脚本,我个人用它来让我的角色行走。该脚本使相机(和绑定的角色)通过简单的头部倾斜或磁铁触发器向前移动。 https://github.com/JuppOtto/Google-Cardboard/blob/master/Autowalk.cs

NOTE: The code in github is for Google Cardboard SDK. So you will have to modify it a little bit if you want to make it compatible to the latest Google VR SDK (few variable name changes).

然而,这是我在等待 Google 发布 DayDream

时推荐的临时修复

实际上你只是在场景中插入GvrViewerMain.prefab,这个预制件改变了你所有的立体渲染相机,你只需要把你的FPSController放在他里面并修改脚本FirsPersonController.cs中的101行。

更改此行

Vector3 desiredMove = transform.forward*m_Input.y + transform.right*m_Input.x;//MODIFIED TO WALK FOR EVER

你只需要将 m_Input.y 替换为 Time.deltaTime,就像这样。

Vector3 desiredMove = transform.forward*Time.deltaTime + transform.right*m_Input.x;//MODIFIED TO WALK FOR EVER

更干净的解决方案:

在你的场景中添加一个摄像头,添加一个characterController组件。; 在相机内添加新脚本:

using UnityEngine;
using System.Collections;

public class movement : MonoBehaviour {

    public float speed = 6.0F;
    public float jumpSpeed = 8.0F;
    public float gravity = 20.0F;
    private Vector3 moveDirection = Vector3.zero;
    void Update() {
        CharacterController controller = GetComponent<CharacterController>();
        if (controller.isGrounded) {
            moveDirection = transform.TransformDirection(Vector3.forward);
            moveDirection *= speed;
            if (Input.GetButton("Jump"))
                moveDirection.y = jumpSpeed;

        }
        moveDirection.y -= gravity * Time.deltaTime;
        controller.Move(moveDirection * Time.deltaTime);
    }
}