- Home /
Question by
hunkyducky · Mar 01, 2020 at 10:48 PM ·
positionspawning
Trying to move the instantiated position
So I am trying to instantiate this angel prefab slightly higher than the position of the spawner object to which this script is attached. The spawner is also instantiating other objects as well. However I can not seem to get the angel objects to be instantiated at a higher position and they just appear at the position of the spawner. Can someone point out what I may be doing wrong? I am new to Unity and C#. Code below:
void SpawnAngel(Transform _angel)
{
Vector3 pos = new Vector3(transform.position.x, transform.position.y + 3f, transform.position.z);
Instantiate(_angel, pos, transform.rotation);
}
Comment
Answer by tormentoarmagedoom · Mar 01, 2020 at 11:23 PM
Hello.
With this code, the instantited object spawns 3 units over the object that contains this script. But 3 units in WorldSpace,
You can always change a position after instntiate:
GameObject NewObj = Instantiate(_angel, pos, transform.rotation);
NewObj.transform.position += Vector3.up*3;
Your answer