- Home /
How to check if an image covers the text?
Hello everyone! I want to change the color of the text that is covered by the image like this:
Changing text is simple using html tags. So the question is: how to know what part of the text is covered by image/rect/etc ? Thanks in advance!
Answer by IgorAherne · Jan 01, 2017 at 01:50 PM
Here is a small example if filler doesn't move but scales from left side, rightwards.
1) move the anchors of filler and text to the center-left side of their rectangles (0, 0.5)
2) combine all anchors to be in the middle of the rect, for both filler and text from their RectTransform.
3) get "width of filler" / "width of text" percentage ratio every update.
4) use percentage ratio from 3) to compute which letter needs to be yellow
Thanks, i was thinking about raycasting at every char in string, but this is total crap) Your idea is much better, thanks again!
Your answer
Follow this Question
Related Questions
Is it possible to give a color to int variables? 1 Answer
Text Changes to Black 7 Answers
UI Text.color not assigning? 2 Answers
How to change color of text relative to current color? 1 Answer
Change MANUALLY GUIText's.text COLOR 2 Answers