Skip to content

Instantly share code, notes, and snippets.

@Ashwinning
Last active February 9, 2016 23:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Ashwinning/d87e014cce668411adb9 to your computer and use it in GitHub Desktop.
Save Ashwinning/d87e014cce668411adb9 to your computer and use it in GitHub Desktop.
Raycast from center - Raycasts to infinity from the center of the screen - Returns RaycastHit object if something is hit, or null if nothing is hit.
	/// <summary>
	/// Raycasts from center.
	/// </summary>
	/// <returns>RaycastHit if something is hit, or null if nothing is hit.</returns>
	/// https://gist.github.com/Ashwinning/d87e014cce668411adb9
	RaycastHit RaycastFromCenter
	{
		get
		{
			// Determine if we hit anything
			Ray ray = Camera.main.ViewportPointToRay(new Vector3(0.5F, 0.5F, 0));
			RaycastHit hit;
			if (Physics.Raycast (ray, out hit)) 
			{	
				return hit;
			}
			else 
			{
				return hit;
			}
		}
	}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment