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

Basic errors

Discussion in 'Scripting' started by LegendaryAccount, Jun 12, 2015.

  1. LegendaryAccount

    LegendaryAccount

    Joined:
    Jun 9, 2015
    Posts:
    10
    Code (JavaScript):
    1. function Update () {
    2.     if(Screen.currentResolution.width > Screen.currentResolution.height){
    3.         guisize = Screen.currentResolution.width;
    4.         transform.localScale.width = guisize;
    5.         transform.localScale.height = guisize;
    6.     }else{
    7.         guisize = Screen.currentResolution.width;
    8.         transform.localScale.width = guisize;
    9.         transform.localScale.height = guisize;
    10.     }
    11. }
    the error is the
    transform.localScale.width = guisize;
    transform.localScale.height = guisize;
    All this script does is squares a UI into a box that fixs on your screen
     
    Last edited: Jun 13, 2015
  2. Duugu

    Duugu

    Joined:
    May 23, 2015
    Posts:
    241
    Please use the code tag.

    And what's your question? :)
     
  3. LegendaryAccount

    LegendaryAccount

    Joined:
    Jun 9, 2015
    Posts:
    10
    I can't find out how to change the width and height of a panel UI. I do not want to change the scale of it I want to change the separate width and height property

    I am new so I have no clue how to do the code tag
     
  4. LegendaryAccount

    LegendaryAccount

    Joined:
    Jun 9, 2015
    Posts:
    10
    In simpler terms, How can I change the width property of a Panel UI
     
  5. Deleted User

    Deleted User

    Guest

    Luckily there's a sticky on the front page of this forum that explains how to use them. :)

    http://forum.unity3d.com/threads/using-code-tags-properly.143875/
     
  6. LegendaryAccount

    LegendaryAccount

    Joined:
    Jun 9, 2015
    Posts:
    10
    Still does not answer my original question
     
  7. Deleted User

    Deleted User

    Guest

    Your original question still does not use code tags
     
  8. LegendaryAccount

    LegendaryAccount

    Joined:
    Jun 9, 2015
    Posts:
    10
    In simpler terms, How can I change the width property of a Panel UI
     
  9. LegendaryAccount

    LegendaryAccount

    Joined:
    Jun 9, 2015
    Posts:
    10
    In simpler terms, How can I change the width property of a Panel UI
     
  10. LegendaryAccount

    LegendaryAccount

    Joined:
    Jun 9, 2015
    Posts:
    10
    In simpler terms, How can I change the width property of a Panel UI
     
  11. Korno

    Korno

    Joined:
    Oct 26, 2014
    Posts:
    518
    Stop spamming the question.

    Anyway what is the error? Does that script just not work. Does unity tell you anything?
     
    Deleted User likes this.
  12. Deleted User

    Deleted User

    Guest

    Yes, don't bump so frequently or other people's question will get bumped down. Everyone should have a chance to get their question seen by the community so they can get answered. Also keep in mind that no one here is under any obligation to assist you so you should try to be polite, comply with the rules of the forum, and provide as much info as possible to others so they have an easier time understanding what's going on.

    Anyway, if you have a look at the docs ( http://docs.unity3d.com/ScriptReference/Transform-localScale.html ) you can see localScale is a Vector3. Vector3 does not have a width and height property. It has an x, y, and z property.
    Also you cannot set just 1 axis of a transform. You need to change the whole thing:

    Code (CSharp):
    1. transform.localScale.x = 4f; // BAD!
    2. transform.localScale.x = new Vector3(5f, transform.localScale.y, transform.localScale.z); // Good!