Skip to main content
added 7 characters in body; edited tags; edited title
Source Link
starikcetin
  • 5.3k
  • 4
  • 27
  • 60

Variable How to match UI Imagebackground size with text length in Unity?

Variable How to match UI Imagebackground size with text length in Unity?

I am making an FPS game in which when you are near an item a UI Text appears at the bottom center of the screen indicating the name of the item and the button to pick it up (let's say [E]).

It works fine but since I couldn't get a clear contrast between the text and the game area (like if the player's standing in front of an egg and the color of the text is white, you can't see the text), I decided to add a black background image to the text.

Now since the item names are of different lengths, I need the image length to match the text length. The background image should just be enough to fit the text How can I go about doing this? Or is there a better way to show a message to the player?

Variable UI Image size in Unity

I am making an FPS game in which when you are near an item a UI Text appears at the bottom center of the screen indicating the name of the item and the button to pick it up (let's say [E]).

It works fine but since I couldn't get a clear contrast between the text and the game area (like if the player's standing in front of an egg and the color of the text is white, you can't see the text), I decided to add a black background image to the text.

Now since the item names are of different lengths, I need the image length to match the text length. The background image should just be enough to fit the text How can I go about doing this? Or is there a better way to show a message to the player?

How to match UI background size with text length in Unity?

I am making an FPS game in which when you are near an item a UI Text appears at the bottom center of the screen indicating the name of the item and the button to pick it up (let's say [E]).

It works fine but since I couldn't get a clear contrast between the text and the game area (like if the player's standing in front of an egg and the color of the text is white, you can't see the text), I decided to add a black background image to the text.

Now since the item names are of different lengths, I need the image length to match the text length. The background image should just be enough to fit the text How can I go about doing this? Or is there a better way to show a message to the player?

Source Link

Variable UI Image size in Unity

I am making an FPS game in which when you are near an item a UI Text appears at the bottom center of the screen indicating the name of the item and the button to pick it up (let's say [E]).

It works fine but since I couldn't get a clear contrast between the text and the game area (like if the player's standing in front of an egg and the color of the text is white, you can't see the text), I decided to add a black background image to the text.

Now since the item names are of different lengths, I need the image length to match the text length. The background image should just be enough to fit the text How can I go about doing this? Or is there a better way to show a message to the player?