So I’ve been working on a game which requires different platforms to instantiate in the correct position (in order to connect each platform’s path). However, whenever I instantiate a platform from the prefab to a child location of another platform prefab, they don’t match. So I tried to figure out why, by simply creating a plane (set the scale to (1,1,2)), and drag it to the prefab folder and delete it off the scene. Created an identical plane on the scene positioned at (0,0,0). Finally attached this script to an empty object on the scene set at (0,0,0).
public Transform platformPrefab;
public Transform onScenePlatform;
void Start () {
Invoke ("Spawn", 0f);
}
void Spawn () {
Instantiate (platformPrefab, Vector3.zero, Quaternion.identity);
print (platformPrefab.transform.position);
print (onScenePlatform.transform.position);
}
Here’s the result:
platformPrefab.transform.position = (-1.7,28.3,4.9), but the Inspector shows (0,0,0).
onScenePlatform.transform.position = (0,0,0).
In the scene (during play), both identical platforms are placed right on each other. What is going on? Where did the platformPrefab.transform.position’s vector come from?
Thank you for reading this.