Ways to Unity 19: Laser or ray detection (for object clicking)
float gunRange = 50f;
RaycastHit hit;
Vector3 ray_start_point = camera_center_point + (Camera.main.transform.forward * 5);
if(Input.GetMouseButtonDown(0) || Input.GetKeyDown(KeyCode.J))
{
if(Physics.Raycast(ray_start_point, Camera.main.transform.forward, out hit, gunRange))
{
laserLine.SetPosition(1, hit.point);
Destroy(hit.transform.gameObject);
}
else
{
laserLine.SetPosition(1, ray_start_point + (Camera.main.transform.forward * gunRange));
}
}
If you want to put a sprite(image) at the center of the camera, you just have to put that image under camera object as a child, and set the start script to
transform.localPosition = new Vector3(0,0,0.5f);