Instantiating prefab at position of other instantiated prefab

Updated on June 1, 2018 in [A] Unity Scripting
Share on Facebook0Tweet about this on TwitterShare on Google+0Share on Reddit0
2 on November 2, 2017

Hi guys,

so I’m currently working on a transport game. I want to generate my track by connecting prefabs (that works already) and then spawn a car or something at an empty gameobject (spawnpoint) in the track prefab. So I searched yesterday and today on Unity Answers and played around with t.position, localPosition and diffrent mathematical approches like calc the width of sprites and so on… Problem is (as usual) that it doesn’t work. The positions in values are the same but in the game view they are by far not the same…

So does anybody have an idea how to fix that (sry) s**t? 😉

@Com: thank you

@Brackeys: Learning more from 5min videos, than in my programming class XD

  • Liked by
Reply
0 on November 4, 2017

As I read your text and the title you probably mean this?:

GameObject car = Instantiate(carPrefab, carPrefab.transform.position, carPrefab.transform.Rotation);
GameObject otherCar = Instantiate(otherCarPrefab, carPrefab.transform.position, carPrefab.transform.Rotation);

Which means to create a car and then another car but on the same position as the first car.

 

  • Liked by
Reply
Cancel
0 on June 1, 2018

Sorry for answering like super late. I had problems logging in here….

Yeah that was kind of the problem. I forgot to factor in that sprites have a ppu… so it was an easy fix. But thank you for your help 🙂

  • Liked by
Reply
Cancel