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.

  1. instantiate your UI element
  2. parent to canvas
  3. set anchored position and/or side delta if needed