- Home /
Increase/Decrease Font Size with distance
I have a script that manages all enemies that are in the world basically i need some function that be able to increase or decrease font size when the player is near or farest from they. here is what im trying to make:
float distance = Vector3.Distance(camera.transform.position, enemy.transform.position);
_text.fontSize = // Do something with distance so the size can increase if near or decrease if farest, basically inversely proportional
First you should probably consider making new canvas for the UI text that has Render Mode set to World Space. This will then render UI objects like normal scene objects and you don't need to change text size manually.
Answer by IcookTacos · Jan 23 at 10:09 PM
,What type of text object are you using? Asuming you can get the font size varibale from the text object why can't you just do something like this:
_text.fontSize = distance;
and with some aditional typecasting / conversion if necessary
Answer by elenzil · Jan 24 at 06:15 PM
what CodesCove is suggesting is probably the path you want. project your 3D entity positions into the 2D UI layer, and render fonts in UI.
Your answer
Follow this Question
Related Questions
How can I get the Time taken for the 2 moving objects to touch each other 2 Answers
Move an object to a specific distance 0 Answers
Hexagon-Grid Distance 2 Answers
a way to create a 360 degree swing 0 Answers