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.

`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
    dappledore and Ali1992616 like this.
  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