Hi guys,
I have a few GUIText objects that have a set font. I also have an @2x version of the same font for retina displays (the title of the font is @2x). The following code is what I’ve written so far, even though it results in an error:
...
oneUsePrice.font = oneUsePrice.font.name + "@2x";
fiveUsePrice.font = fiveUsePrice.font.name + "@2x";
tenUsePrice.font = tenUsePrice.font.name + "@2x";
twentyUsePrice.font = twentyUsePrice.font.name + "@2x";
...
Because it assigns strings to a font value, it results in the following error:
error CS0029: Cannot implicitly convert type `string' to `UnityEngine.Font'
So there needs to be a way to find the font with the name specified on the right side of each assignment, then set the left side to that font. Example in partial pseudocode:
...
oneUsePrice.font = Font.FontWithName(oneUsePrice.font.name + "@2x");
fiveUsePrice.font = Font.FontWithName(fiveUsePrice.font.name + "@2x");
tenUsePrice.font = Font.FontWithName(tenUsePrice.font.name + "@2x");
twentyUsePrice.font = Font.FontWithName(twentyUsePrice.font.name + "@2x");
...
For the record, the reason for wanting to use string parsing to solve this problem (as opposed to setting a Font class variable and using it to swap the @2x font) is because I want to have code that can be reused even in cases where different GUIText objects have different fonts.
Thanks in advance,
MachCUBED
The above works! The only problem is that the text no longer has the right font face, taking on a neutral white arial face while also taking on the target size. It doesn't seem to be loading the desired font texture, even though the text is the right size.
– MachCUBED