Search Unity

Giving a GUI Text a fixed position

Discussion in 'Scripting' started by Beennn, Apr 15, 2011.

  1. Beennn

    Beennn

    Joined:
    Sep 11, 2010
    Posts:
    373
    How can I go about giving a GUI Text a fixed position? so when you change the size of the screen, it adjusts to keep the same distance from the edges?
     
  2. HarvesteR

    HarvesteR

    Joined:
    May 22, 2009
    Posts:
    531
    I myself went through that hassle a few weeks ago...

    GUIText is actually easier than what I had to go through... since it's position is normalized, you can just do this:

    Code (csharp):
    1.  
    2.  
    3. guiText.position = new Vector3(10f / (float)Screen.width, 10f / (float)Screen.height, 0f);
    4.  
    5.  
    this will put it always at 10 pixels from the left border and 10 pixels from the top (or bottom, can't remember) border
    if you're coding in C# those casts are necessary, since Screen.width/height are ints... in JS, there's no such hassles ;)

    Cheers
     
    Phoxxer likes this.
  3. Beennn

    Beennn

    Joined:
    Sep 11, 2010
    Posts:
    373
    aah thanks :) just having some trouble
    forgive my noobynes >.<
     
  4. Joshua_Morrow

    Joshua_Morrow

    Joined:
    Jun 17, 2019
    Posts:
    1
    hey it says that the GUIText does not contain a definition for position ???
     
  5. Beennn

    Beennn

    Joined:
    Sep 11, 2010
    Posts:
    373
  6. StarManta

    StarManta

    Joined:
    Oct 23, 2006
    Posts:
    8,775
    You've stumbled upon an 8 year old thread that predates the current version of Unity UI - any advice above your post is worse than useless for you.
     
    romainfatali30 likes this.