duck

Flashlight Aim Ahead script

May 17th, 2013
195
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class AimFlashlight : MonoBehaviour {
  5.    
  6.     public Transform cam;
  7.     public float rayLength = 100;
  8.     public LayerMask mask;
  9.    
  10.     void Update () {
  11.        
  12.         Ray ray = new Ray( cam.position, cam.forward );
  13.         RaycastHit hit;
  14.        
  15.         if (Physics.Raycast(ray, out hit, rayLength, mask))
  16.         {
  17.             transform.LookAt( hit.point );
  18.             Debug.DrawLine( ray.origin, hit.point, Color.red );
  19.         } else {
  20.             Debug.DrawRay( ray.origin, ray.direction*rayLength, Color.green );    
  21.         }
  22.        
  23.     }
  24. }
Advertisement
Add Comment
Please, Sign In to add comment