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

Re-sizing a Canvas at runtime

Discussion in 'UGUI & TextMesh Pro' started by Trixer, Sep 2, 2014.

  1. Trixer

    Trixer

    Joined:
    Jul 6, 2012
    Posts:
    5
    So I have been trying to figure out how to resize a canvas via code... This is what I did and I thought it would work but it appears to hate me.

    Code (csharp):
    1.  
    2. RectTransform CanvasTransform = (RectTransform)Canvas.GetComponent ("RectTransform");
    3.         CanvasTransform.rect.Set (100, 100, 100, 100);
    4.  
    Anyone know how bad I am doing it wrong?

    Thanks in advance!
     
  2. phil-Unity

    phil-Unity

    Unity UI Lead Developer Unity Technologies

    Joined:
    Nov 23, 2012
    Posts:
    1,226
    what type of Canas are you using? Only World Space can be changed.
     
  3. Trixer

    Trixer

    Joined:
    Jul 6, 2012
    Posts:
    5
    It is a World Space Canvas
     
  4. Trixer

    Trixer

    Joined:
    Jul 6, 2012
    Posts:
    5
    I figured it out

    Setting the SizeDelta property to a new vector2 will resize the canvas :D