- Home /
How to get a GameObject from another GameObject
I have a prefab, and i Want to access this prefab object from another object
the scene hierarchy has:
Player
Camera
Background
Floor(Prefab)
and the prefab hierarchy has:
Floor
DeleteTrigger
CreateTrigger
TransformReference
public class LevelGenerator : MonoBehaviour {
// Start is called before the first frame update
[SerializeField] private GameObject FloorRef;
private void Awake()
{
GameObject g = FloorRef.Find("Floor")
Instantiate(FloorRef, new Vector3(10, 0), Quaternion.identity);
}
}
And what problem are you facing?
Where is LevelGenerator
attached?
What is the object provided in FloorRef
?
Can you provide a screenshot of your hierarchy?
I've already solved, bro;
To get the reference of another hierarchy tree, I need to use the transform of the object in scene's main hierarchy; so I just take as: FloorRef.transform.Find("")
Answer by Lucas_Mondini · May 20 at 11:29 AM
Solved:
To get the reference of another hierarchy tree, I need to use the transform of the object in scene's main hierarchy; so I just take as: FloorRef.transform.Find("")