- Home /
Instantiating UI?
Hey there, I am looking to do something like this below; with UI, how would I go about this? I currently have a canvas that will display the name of a gameobject, its just trying to replicate it, I understand I might need to instantiate the canvas, but unsure how approach it. I don't want to do it manually for every object haha.
This is what I was trying; would I be on the right path?
for (var i = 0; i < part.Length; i++)
{
Vector3 newPos = part[i].transform.position;
//positioning the UI above the object
newPos.y = part[i].transform.position.y + 7f;
newPos.z = part[i].transform.position.z + 2f;
newPos.x = part[i].transform.position.x;
newPos = part[i].transform.position + newPos;
if (part[i].tag == parentTag)
continue;
Instantiate(canvas, newPos ,transform.rotation);
EDIT: I know have the instantiating working pretty much, but they are coming up blank, how would I get all the text to appear.
I have tried looking for a solution, yes, but those links didn't exactly appear when looking around. Anyhow on what you have suggested, by the looks of what they are saying doesn't really help me, as I think I have already them stages done, again I think, maybe I am not reading it right, its more the instantiating I am having bother with. Thanks anyways.
You should not instantiate a canvas for each element. You should :
instantiate a RectTransform
Parent it to a canvas
Set position of it using the links I gave you.
Your answer
![](https://koobas.hobune.stream/wayback/20220612141448im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Instantiated UI prefab in canvas does not render image 1 Answer
How to set a variable on a drag and drop UI element. 0 Answers
How can I instantiate something as a child 2 Answers
How do I destroy the object that was instatiated 1 Answer
An Instantiated UI Button doesn't work; clicking does nothing. 1 Answer