Use a canvas prefab multiple times at the same time
I am not sure if this is even possible, if it is not, can you suggest me another way of doing it? Thanks ahead, and bear with me, I am new haha. So what I want to do is that when I click on a specific object (which appears various times in the scene, at the same time) I want a pop up to, well, pop in every object that I click, and if possible to keep them open even if they still showing in other place of the screen. The pop up right now is a prefab that I created from a panel which contains some buttons and text UI gameObjects. Right now I am using this code to create different canvas, but I am not able to use the prefab in that canvas that I am crating whenever I call OnMouseDown(). And If I get to show it, it won't be functional (Buttons not working)
void OnMouseDown()
{
GameObject canvasGO = new GameObject();
RectTransform canvasRT = canvasGO.AddComponent<RectTransform>();
Canvas canvasCV = canvasGO.AddComponent<Canvas>();
canvasCV.renderMode = RenderMode.ScreenSpaceCamera;
Vector3 pos = transform.position;
pos += transform.forward * 10.0f;
canvasCV.worldCamera = Camera.main;
GameObject buttonGO = new GameObject();
RectTransform buttonRT = buttonGO.AddComponent<RectTransform>();
buttonRT.SetParent(canvasRT);
buttonRT.SetPositionAndRotation(transform.position, transform.rotation);
buttonRT.sizeDelta = new Vector2(2f, 1f);
Image buttonIM = buttonGO.AddComponent<Image>();
buttonIM.sprite = Resources.Load("CarIcon", typeof(Sprite)) as Sprite;
Debug.Log(cityName);
}
If I haven't been clear enough or you need more information about the code please tell me. I don't mind re explaining my problem. Thanks again.