- Home /
Changing position of instantiated prefab from empty gameobject which is the location of the prefab when instantiating.
Hi everyone! I have a problem, I have instantiating prefabs and instantiate it from the location of my empty gameobject, after instantiated one prefab I want to change the position. it depends on the screen orientation if the orientation is landscape the position of the prefab will change and also if the orientation is portrait will change also the position. I appreciate your replies.. TY.
you can start with something like this.
public Transform Prefab;
public Vector3 Pos_Portrait;
public Vector3 Pos_Landscape;
void InstantiatePrefab()
{
//Instanitate the new GamObject at the position of the empty gameobject to which this script is attached
GameObject newGO=Instantiate(Prefab,transform.position,transform.rotation) as GameObject;
if(Screen.orientation == ScreenOrientation.Landscape)
{
newGO.transform.position=Pos_Landscape
}
else
{
newGO.transform.position=Pos_Portrait
}
}
thanks for the answer. I tried this but the instantiated prefab don't change the position. okay, I have 2 empty game objects on my scene view. the first object is the I call it a Spawner which is my script is attached and the second gameobject is the starting position of my instantiated prefab, what happen is only the second gameobject change but the prefab stays on the first position of the second gameobject. what should I do..?