What I’d really like to do is put a translucent rectangle behind the text, but that doesn’t seem to be possible. The text is moved if I set autoSizeTextContainer to it, and you can’t add the Image component if there is already a Text.
I also thought about using the MARK tag but the text paradoxically becomes less visible (gray).
Unfortunately, full CSS support is missing.
Since this is not possible, I would like to at least put a shadow on it to increase visibility.
I know that the default font, LiberationSans SDF has the material Preset “Liberation Sans SDF - Drop Shadow,” and I want to set it to a TextMeshProUGUI object created via code.
Actually I would also be fine with creating a new material (via code) and assigning it.
This is my code
GameObject textGO = new GameObject("MyText");
textGO.transform.SetParent(canvasGO.transform);
TextMeshProUGUI textMeshPro = textGO.AddComponent<TextMeshProUGUI>();
textMeshPro.text = "variable, long and wide text";
textMeshPro.enableWordWrapping = false;
//textMeshPro.autoSizeTextContainer = true;
//////Material materialPreset = Resources.Load<Material>("Liberation Sans SDF - Drop Shadow"); // horror (not error)
//////textMeshPro.fontSharedMaterial = materialPreset;
textMeshPro.fontSize = 40;
textMeshPro.color = Color.white;
textGO.GetComponent<RectTransform>().anchoredPosition = new Vector2(-845, 500); // I want fix on left-top corner (with border).