

Cardboard SDK是谷歌提供虚拟开发包,可以很方便的做出我们的效果.同时我们通过相关的代码达到一些交互行为.总之一句话:站在巨人的肩膀上编程.
1、下载SDK包
前面的博客已经有描述: https://github.com/googlevr/gvr-unity-sdk

2、使用SDK包
找到这两个包:

3、创建第一个VR程序
新建Unity3D项目:导入下载好的SDK包.

将预制物拖入到场景中,展开做如下操作,设置一个Target空物体对象,里面添加一个3D物体,用来定位相机.


这时候在世界场景中添加我们需要的东西,资源等.完成后打包安卓APK,苹果IPA包,安装手机运行
4、交互操作
因为在场景中没办法进行操作,进行一些交互.不用急,SDK已经提供了相应的接口.
1- :给摄像机添加Physics Raycaster组件

2-:添加交互事件系统,删除标准输入

3-:添加一个方块,添加脚本绑定事件
在场景添加一个方块,作为我们的参照物:

using UnityEngine;
using System.Collections;
public class CubeMove : MonoBehaviour {
public void Cube_Move()
{
Debug.Log("1111");
}
}


注意:如果2D图片显示不全可以修改为3D小球或者小方块.
至此:第一个VR小项目开发完毕.

5、EventTrigger
是用来接受来自EventSystem的事件.包含:
Point Enter指当眼睛眼看这个物体,就会调用附在Cube上的脚本.
Point Exit 眼睛离开这个物体,调用附在Cube上的脚本.
网友评论