Hi, so I am doing this as it is a special design request that the buttons be smaller on certain devices. I have to manage this manually and hence the scaling of anchors. They are already using a Fixed size root but on some devices they have to change size for different layout designs.
I just testing my code using the older "UISprite" and it works. "UI2DSprite" does not work.
If you create a Sprite with a UIButton component and set a hover sprite and give the buttons a Unified anchor. Then attach a custom component and add the following code to its "Start()" method you will see that as you hover over the button, the new sprite appears and is also scaled based upon the anchor.
void Start() {
UISprite sp = gameObject.GetComponent<UISprite>();
if( sp.isAnchored ) {
sp.leftAnchor.absolute /= 2;
sp.rightAnchor.absolute /= 2;
sp.bottomAnchor.absolute /= 2;
sp.topAnchor.absolute /= 2;
sp.ResetAnchors();
sp.UpdateAnchors();
}
}
If you do the same as above but add a UI2DSprite, when you hover over the hover state does not appear scaled but in its original size and when you roll off the button the normal state also appears in its original size. The anchors are ignored.
Would it be possible to have the UI2DSprite work like the UISprite?
Also I tried the code you suggested above on my hover but due to my anchors scaling, the buttons move causing an "hoverOn" > "hoverOff" > "hoverOn" > "hoverOff" loop.