Hi,
I am instantiating a GameObject (called BattleStation) and then attaching it to a parent (the GameObject acting as the parent of the whole scene). After this I then try to position the BattleStation GameObject using transform.position but the BattleStation does not move but adjusts it’s origin point by the amount that is supposed to be moved. Is this normal behaviour?
The code for this is:
using UnityEngine;
using System.Collections;
public class EntryPoint : MonoBehaviour
{
GameObject playerBase;
void Update()
{
if(playerBase == null)
{
playerBase = (GameObject) Instantiate(Resources.Load("BattleStation"));
playerBase.transform.parent = gameObject.transform;
playerBase.transform.position = new Vector3(15f, 0f, 0f);
}
}
}
The white line in the image represents the origin point of the scene (0, 0, 0), and the red line represents the origin point of the BattleStation GameObject. Notice that it is not at the centre of the GameObject where it should be and that it has moved 15 units on the x-axis.
Now if I wait a frame then re-position my BattleStation GameObject then it works as expected.
using UnityEngine;
using System.Collections;
public class EntryPoint : MonoBehaviour
{
GameObject playerBase;
void Update()
{
if(playerBase == null)
{
playerBase = (GameObject) Instantiate(Resources.Load("BattleStation"));
playerBase.transform.parent = gameObject.transform;
}
else
{
playerBase.transform.position = new Vector3(15f, 0f, 0f);
}
}
}
In this image the BattleStation has moved 12 units in the x axis while its origin point has remained at the centre of the GameObject. This is what I expect the first bit of code should have done.
So my question is should re-positioning a GameObject after instantiation move it’s origin point instead of actually moving the GameObject itself?