我正在制作360视频,需要使用raycast来选择菜单选项 . 我画了光线投射,似乎没问题 . 但是,没有发现任何检测 . 按钮位于世界视图中并具有网格对撞机并且启用了“触发器” .
以下是附加到主摄像头的脚本:
using System.Collections;
using System.Collections.Generic; using UnityEngine;
public class VrEyeRaycaster : MonoBehaviour {
public string objectCollided;
// Use this for initialization
void Start()
{
}
// Update is called once per frame
void Update()
{
//create the ray to cast forward
RaycastHit hit;
Vector3 origin = transform.position;
Vector3 direction = transform.TransformDirection(Vector3.forward)*20;
Ray ray = new Ray(origin, direction);
Debug.DrawRay(origin, direction, Color.green);
if (Physics.Raycast(ray, out hit, 100f))
{
objectCollided = hit.collider.gameObject.name;
print(objectCollided);
}
else
{
string s = "Nothing hit by RayCaster";
print(s);
}
}
}
我已经尝试将相机及其容器放入世界画布,但它也没有用 . 我可能会出错的任何想法???我实际上无法看到光线是否正在按下按钮,因为我只能看到场景窗口中的光线并且只能看到游戏窗口中的按钮 .