Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- public class AimFlashlight : MonoBehaviour {
- public Transform cam;
- public float rayLength = 100;
- public LayerMask mask;
- void Update () {
- Ray ray = new Ray( cam.position, cam.forward );
- RaycastHit hit;
- if (Physics.Raycast(ray, out hit, rayLength, mask))
- {
- transform.LookAt( hit.point );
- Debug.DrawLine( ray.origin, hit.point, Color.red );
- } else {
- Debug.DrawRay( ray.origin, ray.direction*rayLength, Color.green );
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment