Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

CS0117: 'Camera' does not contain a definition for 'Main'

Discussion in 'Scripting' started by jjthegamertv, May 11, 2020.

  1. jjthegamertv

    jjthegamertv

    Joined:
    Apr 17, 2020
    Posts:
    7
    (Sorry if i may have posted this in the wrong category)

    In my Camera Follow Script, I'm using C# and a tutorial for a game. In the tutorial, the guy writing the script doesnt get the same error as me, despite having the same code.
    Code (CSharp):
    1.     void Start()
    2.     {
    3.         camHeight = Camera.main.orthographicSize * 2;
    4.         camWidth = camHeight * Camera.Main.aspect;
    5.        
    6.         float leftBoundsWidth = leftBounds.GetComponentInChildren<SpriteRenderer> ().bounds.size.x / 2;
    7.         float rightBoundsWidth = rightBounds.GetComponentInChildren<SpriteRenderer> ().bounds.size.x / 2;
    8.        
    9.         levelMinX = leftBounds.position.x + leftBoundsWidth + (camWidth/2);
    10.         levelMaxX = rightBounds.position.x - rightBoundsWidth - (camWidth/2);
    11.     }
    camWidth = camHeight * Camera.Main.aspect; seems to be triggering it. If you need the entire code ill edit(?) this post with a hastebin link to it. Also, if you need any extra information I'll be glad to send. (Note that I know little of C#, hence why I'm watching a tutorial.)
     
    WaSSoup likes this.
  2. Brathnann

    Brathnann

    Joined:
    Aug 12, 2014
    Posts:
    7,151
    The funny thing is, you have it right on line 3, but wrong on line 4. I'll give you a hint. Caps matter.
     
  3. jjthegamertv

    jjthegamertv

    Joined:
    Apr 17, 2020
    Posts:
    7
    Oh god, i didn't notice that. I thought it was just some outdated code that didnt get picked up my the api updater thing. Thanks!
     
  4. Brathnann

    Brathnann

    Joined:
    Aug 12, 2014
    Posts:
    7,151
    It never hurts to have another pair of eyes on occasion, but this will help you be aware of the caps. :)
     
    jjthegamertv likes this.