我已经编写了一个简单的光线投射脚本,附加到Oculus运动控制器的手中。这个想法是-控制器就像一个真空吸尘器,它吸走了预制好的物体,叫做“Eosinophil2(克隆)”。
在运动控制器之外的一些测试中,这是可行的。
我遇到的麻烦是当我将光线投射脚本放入运动控制器中时。只有当我在守卫者边界旁边时,它才能像预期的那样工作。
我已经打开和关闭了边界,看看这是否解决了什么问题,但没有。
我检查了光线投射线是否在正确的方向上--确实如此。
有什么想法吗?
void FixedUpdate()
{
// OVRInput.SetControllerVibration(.3f, 0.3f, OVRInput.Controller.RTouch);
var up = transform.TransformDirection(Vector3.forward);
//note the use of var as the type. This is because in c# you
// can have lamda functions which open up the use of untyped variables
//these variables can only live INSIDE a function.
RaycastHit hit;
Debug.DrawRay(transform.position, up * 20, Color.green,1);
if (Physics.Raycast(transform.position, up, out hit, 20))
{
if (hit.collider.gameObject.name == "Eosinophil2(Clone)")
{
OVRInput.SetControllerVibration(.3f, 0.3f, OVRInput.Controller.RTouch);
hit.collider.gameObject.transform.position = Vector3.MoveTowards(hit.collider.gameObject.transform.position, transform.position, 20 * Time.deltaTime);
}
else
{
//OVRInput.SetControllerVibration(0, 0, OVRInput.Controller.RTouch);
}
}
}
private void OnTriggerEnter(Collider other)
{
if (other.gameObject.transform.name == "Eosinophil2(Clone)")
{
this.gameObject.GetComponent<AudioSource>().Play(0);
Debug.Log("works");
Destroy(other.gameObject);
Debug.Log("HIT ONE!");
hitRate++;
}
}`enter code here`发布于 2018-08-10 15:45:48
这个故事的寓意--从头开始构建场景。
在所述构建场景中使用OVRCameraRig预制件。
使用来自Oculus的预先构建的场景可能对一个人的健康、时间和代码有害。
我希望有一天这能帮助到某个人。
https://stackoverflow.com/questions/51769941
复制相似问题