- Home /
How do you Instantiate Text as Child of Canvas c#
So, I'm trying to make a Cookie Clicker clone so that I become more comfortable with the U.I. in Unity and altogether scripting.
What I want to happen is this:
You click on the button, and text appears at the cursor position.
The spawned text should display the amount of cookies created with the click. (For example: "+1 cookie")
A bonus would be if the text would also float upwards and slowly fades away, but isn't 100% necessary right now.
I managed to spawn the text at the cursor position, BUT because it is not a child of the Canvas, it doesn't display anything, and therefore is absolutely worthless.
I've been trying to figure this out for quite some time now, and it's starting to really annoy me. I thank you for your contribution, and hopefully this is just some simple problem that I'm overthinking.
@noorudheen I'm trying to create a new text that spawns at the mouse position, not change the text component of the button.
Also, transform.parent doesn't seem to work for U.I. objects.
@SiJiGamer nonsense, for UI elements you should work with recttransform and not transform, and use setParent().
Answer by YoungDeveloper · Aug 11, 2015 at 06:44 PM
instantiate your UI element
parent to canvas
set anchored position and/or side delta if needed
Your answer
Follow this Question
Related Questions
Instantiate prefab text into Canvas 2 Answers
How do I change scene with two ui canvas text 2 Answers
Instantiated GameObject gets spawned as a child 2 Answers
Distribute terrain in zones 3 Answers
Instantiating as a child error 1 Answer