2

I am trying to re-create my game using the NGUI plugin for Unity and I like it a lot so far, but am in the mist on this one.

I have an UIPanel called games and I want programmatically to change it size but don't know how to get into the parameters...

I have tried like this, but with no luck:

GameObject.Find("Games").UIPanel.size.x = 300;

Also tried this, but with no luck:

GameObject.Find("Games").GetComponent("UIPanel").clipping.size.x = 300;

This doesn't work and I don't know how to do this... Any help is appreciated :-)

CodeSmile
  • 64,284
  • 20
  • 132
  • 217
Mansa
  • 2,277
  • 10
  • 37
  • 67

3 Answers3

0

Try to set clipRange property.

GameObject.Find("Games").GetComponent("UIPanel").clipRange = new Vector4(x, y, z , w); 
PeakCoder
  • 852
  • 8
  • 20
0

You can try one of two things.

First is by setting the absolute values of the corners of the UIRect (UIPanel inherits from UIRect)

mPanel.localCorners[0].Set(0.5f, 0.5f, 1f); //this is bottom_left corner

You can also use worldCorners instead of localCorners. The other option is to adjust the anchor values, if you panel is anchored.

mPanel.leftAnchor.absolute = 200;
Dover8
  • 607
  • 3
  • 17
0

Setting the baseClipRange manually is not recommended (due to documentation), but you can produce full clip updating by invoke clipOffset setter (it does the necessary internals).

I did the same, when I wanted to clip a UIPanel with a moving UIWidget.

// Set clipping region to some widget dimension.
panel.baseClipRegion = new Vector4(
    clippingWidget.cachedTransform.localPosition.x,
    clippingWidget.cachedTransform.localPosition.y,
    clippingWidget.width,
    clippingWidget.height
    );

// Invoke culling.
panel.clipOffset += Vector2.one; 
panel.clipOffset -= Vector2.one;
Geri Borbás
  • 15,810
  • 18
  • 109
  • 172