Created
April 21, 2020 14:05
-
-
Save openroomxyz/624a58244dbdb996f20907097a261e8b to your computer and use it in GitHub Desktop.
Unity : How do you add gameObject as child to other?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[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