0

I am new to Unity and I learned somehow now.

Btw I am struggling with a problem.

The problem is, I've created the clone GameObject using Instantiate and it works well. But I want to implement the OnMouseHover or Click for every cloned object to show a pop-up. How can I refer to the clicked object which I've created at runtime? Thank you!

void Awake(){
    for (int i = 0; i < 5; i++)
    {
        myPdfPrefabClone = Instantiate(myPdfPrefab, new Vector3(x, 0, x), Quaternion.identity) as GameObject;
        myPdfPrefabClone.name = "" + x;
        Debug.Log(myPdfPrefabClone.transform.position);

        Debug.Log("name " + myPdfPrefabClone.name);

        x = x + 2.5F;
    }

}
Fahry Mohammed
  • 599
  • 5
  • 18
  • Check how to use raycast for detecting objects with mouse, when you achieve this, you can enable/disable "popup" gameObjects within a function – Thalthanas Jul 10 '18 at 06:11
  • See the `ClickDetector` script from the duplicate. Now, all you have to do is `myPdfPrefabClone.AddComponent();`. The `OnPointerEnter` function should give you what you are looking for. – Programmer Jul 10 '18 at 06:34
  • @Programmer I've assigned the scripts for clone GameObjects at runtime. I just tested out the network call and other color changing. It's working but the not detecting the tab or click functions. – Fahry Mohammed Jul 10 '18 at 09:41
  • Didn't work anything but I've added a **script** and **SphereCollider** while cloning the **GameObject**. After that only the tab function working for every cloned object. – Fahry Mohammed Jul 10 '18 at 09:53
  • When you try an answer an it doesn't work, add EDIT to your question and then include he new code to show what you have tried. – Programmer Jul 10 '18 at 10:03
  • Finally, I've solved the problem. But there is no way to explain since the question marked as duplicate. – Fahry Mohammed Jul 10 '18 at 11:22

0 Answers0