I copied code from the documentation into a new C# class named example:
using UnityEngine;
using System.Collections;
public class example : MonoBehaviour {
public Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
public RaycastHit hit;
void Example() {
if (Physics.Raycast(ray, out hit, 100))
Debug.DrawLine(ray.origin, hit.point);
}
}
And guess what it spits out:
How is this possible I know that Camera.main has always worked, so my question is could this be a bug?
Because if it is I canât continue working.
The only thing I imagine it could be is that I still have not updated to the latest version.
Help is greatly appreciated!
I made a stupid mistake by having a class for my camera in there called Camera. Stupid 
1 Like
i have exact same problem i dont understand what you can you describe me
i want access my camera form Camera.main but main is not showup
Create a new thread and post your code with some info of your basic scene structure setup.
Be sure you havenât in your project a class named âCameraâ, which would override the UnityEngine.Camera class, as SimonAlkemade2 had.
@SimonAlkemade2: However your code is logically wrong, cause youâre creating a Ray from the Input.mousePosition when your component is first initialized. You may want to move the assignment of ârayâ into the function Example to be able to make a ray at runtime when you call the function (Iâd move both variable declarations inside the function since I suppose you donât need them from outside the function).
2 Likes
Thank you you are my savior
I looked 30min for the answer and then i realize its just my scriptâs name 