xxxxxxxxxx
// How to check from Camera
using UnityEngine;
public class CheckRaycast : MonoBehaviour {
RaycastHit hit;
Ray ray;
void Update()
{
ray = Camera.main.ScreenPointToRay(Input.mousePosition);
if(Physics.Raycast(ray, out hit))
{
Debug.Log(hit.collider.gameObject.name);
}
}
}
xxxxxxxxxx
using UnityEngine;
public class Raycaster : MonoBehaviour {
void Update() {
RaycastHit hit;
if (Physics.Raycast(transform.position, -Vector3.up, out hit))
hit.transform.SendMessage ("HitByRay");
}
}
//The object would have a script like this:
using UnityEngine;
public class ObjectHit : MonoBehaviour {
void HitByRay () {
Debug.Log ("I was hit by a Ray");
}
}