Permalink
Cannot retrieve contributors at this time
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?
DMD2542-Project003-RaycastingRepo-JacobTomassi/DMD2542-Project003-Raycasting-JacobTomassi/Assets/Let's Try Shooter/Scripts/CompletedScripts/RayViewerComplete.cs
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
26 lines (18 sloc)
931 Bytes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} | |
} |