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
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Anchoring & scale problems with GUI

Discussion in 'Immediate Mode GUI (IMGUI)' started by JackSparrow1, Jul 8, 2015.

  1. JackSparrow1

    JackSparrow1

    Joined:
    Jun 21, 2015
    Posts:
    16
    Unity 4.6 JavaScript

    Im trying to anchor GUI elements that are all displayed and controlled through script.
    My main screen & H.U.D. are anchored fine & scale perfectly, but i can not get the GUI to stay in a fixed position or for it to scale. The best ive been able to come up with is close to being fixed, but is not truely.
    Here is my code, if anyone can point me in right direction to achieve this without using the editor to place box,buttons ect, i would be very gratefull.

    function Start()
    {

    Camera.main.aspect = 2248f / 1280f;

    a = (Screen.width/2 +0f*Screen.height);
    b = (Screen.height/2 +0f/Screen.width);

    }


    function OnGUI()
    {

    GUI.Box (new Rect (a/213*20,b/39*20,Screen.width/18 +0f*Screen.height,Screen.height/18 +0f/Screen.width), "" +score);

    }

    as you can see this is very messy and a real nightmare to position correctly, and it dont anchor/scale precicly.
     
  2. JackSparrow1

    JackSparrow1

    Joined:
    Jun 21, 2015
    Posts:
    16