IMHOTEP Framework
 All Classes Namespaces Functions Variables Enumerations Enumerator Properties Pages
ShootCameraRay.cs
1 using UnityEngine;
2 using System.Collections;
3 using UnityEngine.EventSystems;
4 using System.Collections.Generic;
5 
6 public class ShootCameraRay : MonoBehaviour {
7 
8  // Use this for initialization
9  void Start () {
10 
11  }
12 
13  // Update is called once per frame
14  void Update () {
15 
16  if (Input.GetKeyDown(KeyCode.Y) )
17  {
18  RaycastHit hit;
19  Ray ray = new Ray(Camera.main.transform.position, Camera.main.transform.forward);
20  LayerMask onlyMeshViewLayer = 1000000000; // hit only the mesh view layer
21 
22  if (Physics.Raycast(ray, out hit, Mathf.Infinity, onlyMeshViewLayer))
23  {
24  //Debug.Log("Hidden object: " + hit.collider.gameObject);
25  Vector3 offset = new Vector3(0.1f, 0.1f, 0.1f);
26  Debug.DrawLine(Camera.main.transform.position + offset, hit.point, Color.red, 10f);
27  }
28  }
29  }
30 }