我试图从来源内部投射射线到球体。 我的主相机位置(0,0,0) 球体位置(0,0,0)半径:300 我想知道hit.position和hit.collider.gameobject 我正在尝试下面的教程。 http://answers.unity3d.com/questions/129715/collision-detection-if-raycast-source-is-inside-a.html碰撞检测如果Raycast来源在对撞机内
即使我试过教程,我无法从控制台窗口看到理想的结果。 (在我的控制台窗口中没有Debug.Log结果) 我该怎么做?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class EyeTrackingPoint : MonoBehaviour
{
public float sphereRadius = 300; // position(0,0,0) radius 300
public GameObject screen3D; // sphere
public void Update()
{
Camera cam = Camera.main; // position(0,0,0)
RaycastHit hit;
Ray ray = new Ray(cam.transform.position,cam.transform.rotation * Vector3.forward * sphereRadius);
ray.direction = -ray.direction;
if (Physics.Raycast(ray,out hit)&&hit.collider.gameObject.Equals(screen3D))
{
Debug.Log(hit.point);
}
}
}
谢谢您的阅读。