How to assign a canvas's text to a prefab?
I understand I can't just drag and drop the Text child of a canvas onto a prefab, so how can I assign it to the prefab?
I tried using this code:
MessageText = GameObject.Find ("PowerUpMessageCanvas").text;
but it kept changing .text to .guitext. How can I fix this?
Answer by dhore · Jan 29, 2016 at 06:00 PM
I take it you want to replace a prefab with a gameobject which is more "up to date" ?
If so, this is what you want: PrefabUtility.ReplacePrefab
What I want is to have it display text when the player gets a powerup. I created a Canvas called 'PowerUp$$anonymous$$essageCanvas' and it has a Text gameobject child. Now on my player tank prefab, I want to write directly to that Text gameobject, but since that gameobject is in the hierarchy and the tank is a prefab, I can't just assign the text to the tank by doing Public Text $$anonymous$$essageText; So how can I tell it to find that text gameobject and write to it?
Your answer
![](https://koobas.hobune.stream/wayback/20220612062231im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Scoring system not working? 1 Answer
How to attach text to moving prefab so that both move together? 1 Answer
Adding Text to Prefab 0 Answers
Score system not working 1 Answer
Changing a Prefab's Text component seems to be broken. 1 Answer