Creating objects dynamically

Hi everyone ! I’m very new to Unity ! I am working a simple game where there is requirement for dynamic creation of objects. To be exact need to create pipes from user swipes so that objects could move through it later on. Any help/suggestion/insight/anything is highly appreciated !

You’ll want to look into creating “prefabs”. This will allow you to instantiate (dynamically create) the object as many times as you need to based on whatever criteria your game logic requires. Without diving into specifics the general way to instantiate an object is as follows:

Instantiate(prefab, position, rotation);

prefab is a reference to a prefab you’ve created in your project.
position is a Vector2 or Vector3 position in which your object will spawn at.
rotation is the starting rotation, which you can just set to Quaternion.identity most of the time.

I hope this helps!

References:

Thanks a lot for the reply ! ‘Prefab’ is is really awesome ! But i was looking for creation of objects of various size, shape and dimensions like a pipe which can be constructed in any way between two points. Can this be achieved using ‘Prefabs’ ??

You could use a prefab for the beginning and end of the pipe, instantiating the beginning and end pieces when the player starts touching and the end would simply have to follow the touch movement of the player and when they release it would essentially be placed in that position. The inner part of the pipe would probably have to be line renderer or a repeating texture since we can’t repeat sprites yet (but it is planned for a future release).

Thanks a lot ! Will definitely try it !

Good luck! You actually got my “let’s experiment with Unity” juices flowing so I’m going to attempt to make an example. I’ll post it for you here and on my site when I’m done.

That’s cool ! and yes ‘Unity is awesome’ !..thanks again !