Skip to content

Instantly share code, notes, and snippets.

@openroomxyz
Created April 21, 2020 14:05
Show Gist options
  • Save openroomxyz/624a58244dbdb996f20907097a261e8b to your computer and use it in GitHub Desktop.
Save openroomxyz/624a58244dbdb996f20907097a261e8b to your computer and use it in GitHub Desktop.
Unity : How do you add gameObject as child to other?
[SerializeField] GameObject towerParentTransform;
private void InstantiateNewTower(Waypoint baseWaypoint)
{
var newTower = Instantiate(towerPrefab, baseWaypoint.transform.position, Quaternion.identity);
newTower.transform.parent = towerParentTransform.transform; //THIS LINE
}
//or better
[SerializeField] Transform towerParentTransform;
private void InstantiateNewTower(Waypoint baseWaypoint)
{
var newTower = Instantiate(towerPrefab, baseWaypoint.transform.position, Quaternion.identity);
newTower.transform.parent = towerParentTransform; //THIS LINE
baseWaypoint.isPlaceable = false;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment