Skip to content
Permalink
7aa1c449e2
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
26 lines (18 sloc) 931 Bytes
using UnityEngine;
using System.Collections;
public class RayViewerComplete : MonoBehaviour {
public float weaponRange = 50f; // Distance in Unity units over which the Debug.DrawRay will be drawn
private Camera fpsCam; // Holds a reference to the first person camera
void Start ()
{
// Get and store a reference to our Camera by searching this GameObject and its parents
fpsCam = GetComponentInParent<Camera>();
}
void Update ()
{
// Create a vector at the center of our camera's viewport
Vector3 lineOrigin = fpsCam.ViewportToWorldPoint(new Vector3(0.5f, 0.5f, 0.0f));
// Draw a line in the Scene View from the point lineOrigin in the direction of fpsCam.transform.forward * weaponRange, using the color green
Debug.DrawRay(lineOrigin, fpsCam.transform.forward * weaponRange, Color.green);
}
}