- Home /
Keep getting the Error: Camera' does not contain a definition for `mainCamera'
I have no clue why. Here's the code corresponding with the error:
Vector3 camPos = Camera.mainCamera.WorldToScreenPoint(transform.position);
Also I get the eroor: The name `CameraOperator' does not exist in the current context
And here's the code the corresponds with that error:
camPos.y = CameraOperator.InvertMouseY(camPos.y);
selected = CameraOperator.selection.Contains(camPos);
Whenever an error tells you that X does not contain a definition for Y, then just look in the docs for X to see what the definitions actually are. An error about X not existing in the current context means exactly that: it does not exist. You haven't defined it.
Answer by DarkEdge · Apr 08, 2015 at 10:14 PM
I had the same error. As it turns out, if one of your scripts is called Camera, it looks for Camera.main inside that script, instead of using the built-in Camera class. So either rename your Camera script, or add the UnityEngine namespace in front of your call:
UnityEngine.Camera.main.WorldToScreenPoint(transform.position);
Answer by fafase · Apr 05, 2013 at 07:49 PM
Because you want to use:
Camera.main.members;
That came up with the new error: Camera' does not contain a definition for
main'
Well, did you remove and add a camera? If so, is the camera tagged as $$anonymous$$ainCamera. As mentioned in the other comment a lot of information are available from the docs:
http://docs.unity3d.com/Documentation//ScriptReference/Camera-main.html
Your answer
![](https://koobas.hobune.stream/wayback/20220613095752im_/https://answers.unity.com/themes/thub/images/avi.jpg)