This question is kind of continued from this one:
I can instantiate an object to local space and it works with the following code:
private void AddGoalStalker()
{
GameObject goalStalker = Instantiate(goalStalkerPrefab, hazardDirectory, false) as GameObject;
Vector3 pos = new Vector3(hole.transform.position.x, goalStalker.transform.position.y, hole.transform.position.z);
goalStalker.transform.position = pos
}
However, the below code doesn’t work even though it’s essentially doing the same thing?
private void AddGoalStalker()
{
Vector3 pos = new Vector3(hole.transform.position.x, goalStalkerPrefab.transform.position.y, hole.transform.position.z);
InstantiateObject(goalStalkerPrefab, hazardType.GoalStalker, pos);
}
private void InstantiateObject(GameObject prefab, Hazard hazard, Vector3 pos)
{
GameObject obj = Instantiate(prefab, hazardDirectory, false) as GameObject;
float rot = RandomRot(hazard);
obj.transform.position = new Vector3(pos.x, pos.y, pos.z);
obj.transform.Rotate(Vector3.up, rot, Space.Self);
}
Does anyone know why this doesn’t work? I need to do it the second way for additional checks in the InstantiateObject() method that won’t affect the positioning.
Any help will be really appreciated