Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice
  3. Dismiss Notice

`Screen' does not contain a definition for `width'

Discussion in 'Immediate Mode GUI (IMGUI)' started by Scarlier, Aug 28, 2011.

  1. Scarlier

    Scarlier

    Joined:
    Aug 28, 2011
    Posts:
    5
    Hi,

    i am trying out unity and wanted to read the current screen width. but what i see in examples is using Screen.width
    but i get the following error when i try to use it `Screen' does not contain a definition for `width'

    when i use the following code

    void OnGUI() {
    Debug.Log(Screen.width);
    }

    what do i need to be able to read Screen.width / height?
     
  2. Jessy

    Jessy

    Joined:
    Jun 7, 2007
    Posts:
    7,325
    You named one of your classes Screen, didn't you? You can check you class names against the index, so that you don't duplicate them.
     
    Last edited: Aug 28, 2011
  3. Scarlier

    Scarlier

    Joined:
    Aug 28, 2011
    Posts:
    5
    aaaaah :) indeed thanks got i working now :)
     
  4. Jessy

    Jessy

    Joined:
    Jun 7, 2007
    Posts:
    7,325
    Also, keep in mind that Screen.width / height isn't going to get you what you want, because they're both integers, and integer division only gives you the floor of the result, as an integer. You'll want something like
    Code (csharp):
    1. (float)Screen.width / Screen.height
    instead.
     
    Ali1992616 likes this.
  5. Scarlier

    Scarlier

    Joined:
    Aug 28, 2011
    Posts:
    5
    thnx for the heads up
     
  6. chenz6_unity

    chenz6_unity

    Joined:
    Feb 13, 2024
    Posts:
    1
    Thanks for the help!