How can I make a texture rect expand to the left (in game) upon receiving some information?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By radradish

I’m trying to make a Seiken Densetsu 3 style power bar, which is basically two power bars on both sides of the character’s portrait in the ui, but I’m having trouble making one of the power bars fill in (I’m using a texture rect) in the correct direction.

In Seiken Densetsu 3, when the player successfully connects an attack with the enemy, the power bar on the right of the character portrait expands to the right, and simultaneously, the power bar on the left of the character portrait expands to the left (the two power bars are basically mirrors of each other.)

I’ve tried setting the grow direction of the left power bar both in the inspector and in code, but no matter what I do, the left power bar keeps filling in to the right.

Here’s a picture of Seiken Densetsu 3’s ui. The power bars are the dark vertical strips next to the character portrait, which is in the middle. This is what I’m trying to make:

Imgur

This is what’s going wrong when I try to execute the same thing:

Imgur

Any advice on what to do?

:bust_in_silhouette: Reply From: exuin

Set scale.x to -1.
Edit: Also, you’ll have to change the position of the texturerect too. Or you can use a shader to duplicate the right bar.

Edit edit: I mean, duplicate the right bar and set the duplicate’s scale to -1.

I set scale.x to -1 like you said, and changed the position of the texturerect. It worked! Thank you for the help!

radradish | 2021-01-21 20:53