I cannot see anywhere in the API a method for finding a game object child of a game object (not a component). I tried using FindByTag, but it then finds the same object in another instance of the parent’s gameobject.
More detail:
I have two objects, a player and an enemy. They both have a child gameobject tagged “Right_Hand”. If I do FindByTag on the enemy it is finding the Right_Hand of the player…
Actually I asked how one script can access another in a specific situation. I could not get a script from a child object to access the script on a parent object.
I understand global variables, but they would not work in this case.
The other way around works fine, because you just call GetComponentInChildren, but there is no GetComponentInParent.
The second issue I encountered was that the Find method on my models transform, would not Find the “hand”. If I hard code the path using
Thanks - that is a better way of doing it that I was (using a recursive method to search the whole hierarchy down from the main game object).
As for my first issue:
Below I have the prefab - spell_casting_bolts - it has one script attached “SpellInformation”. Now I have a script in casting_right_nuke which you can see in the inspector. It has a script called Hand Right Casting Spell, which needs to access SpellInformation. But I cannot in that script get a reference to SpellInformation (like I could the other way with GetComponentInChildren(…) .