I am trying to instantiate characters with code that works well for me, if I instantiate that prefabricated character, but when the character is on the scene it has 3 parameters and when I return it to a prefabricated one only 2 are passed and that is giving me problems. I would like to know if there is any way to find that game object, I was dealing with GameObject.GetChild.FindGameObjectWithTag (“”); and he doesn’t find it or it will be because the object is a child of another game object. I need to find the Pipe System object when it is instantiated, Sorry my English is not so good. I hope it is understood with the images
If you want to find it by tag :
GameObject.FindGameObjectWithTag("Untagged");
I don’t see in the screenshot that you gave any tag to the Player White
So doing it this way is wrong since it will find you any gameobject that is untagged and by default gameobjects are untagged.
So add a tag to Player White for example Player White then change the Tag from Untagged to Player White
Then you can do :
GameObject.FindGameObjectWithTag("Player White");
When the gameobject have a tag and you find it by tag it will find it even if it’s a child.
Now to get access to the parameters in the script Player just do :
GameObject.FindGameObjectWithTag("Untagged").GetComponent<Player>().PipeSystem;
Or
GameObject.FindGameObjectWithTag("Untagged").GetComponent<Player>().Velocity;
and then you can do for example :
GameObject.FindGameObjectWithTag("Untagged").GetComponent<Player>().Velocity = 20f;
1 Like