Search Unity

Instantiation problem

Discussion in 'Scripting' started by qaddah, Jul 17, 2019.

  1. qaddah

    qaddah

    Joined:
    Jul 17, 2019
    Posts:
    2
    Hello, i need to instantiate an object i designed as an endless runner tile..but its inclined (rotated 35 degrees on the Y-axis so that it will serve as an infinite straight hill) i couldn't find a way to spawn it properly without it being messed up because i don't know how to instantiate on the local axis. please help me instantiate it on its local axis not matter what rotation it has. im still new to instantiate function handling :(
     
  2. csofranz

    csofranz

    Joined:
    Apr 29, 2017
    Posts:
    1,556
    I think you are looking at this issue slightly worng. You can't spwan objects on their local axis - you usually spawn objects globally. BUT - and this is the good news - you can then parent them to another object, and then use the transform.localposition and transform.localRotation to manipulate them local to their parent. So you are probably already 90% where you want to be.

    A good way to figure this out is to create a new Scene, and simply experiment. Use an existing object and your prefab, and then start writing spawn scripts that first spawn, then spawn and parent, then spawn, parent, move locally etc.You'll quickly see how parenting, local and global attributes work together.