- Home /
[Solved] How to Dynamicaly assemble an Object in your Resource Folder
Am trying to dynamically create a platform but I want the tiles to randomly assemble depending on length and type of tile/object I want to be part of the platform.
Example = stands for a piece of the platform + equals object
====
==+==
======
I have a Parent object in my resource folder which contains all I need to make my platform work But I need to dynamically make Sprites / Objects to be children of this parent before I instantiate the entire object.
Any Ideas I been looking and trying different things but no success yet. I already tried just to see but just instantiates the parent without the child :(
public class testing : MonoBehaviour { public GameObject parent; public GameObject child;
void Start () {
Vector3 spawnPos = new Vector3(transform.position.x, transform.position.y, 0f);
//child = (GameObject)Instantiate(child, spawnPos, Quaternion.identity);
// parent = (GameObject)Instantiate(parent, spawnPos, Quaternion.identity);
child.transform.parent = parent.transform
Instantiate(parent, spawnPos, Quaternion.identity);
}
Answer by Rickstrife · May 18, 2015 at 10:32 AM
I got IT!!
I basically had a dummy parent and extended from my Platform class to GeneratedPlatform and had a public array that held references to tiles. Before Instantiate I set the public array to a dynamically created array with tile refs and correctly build my platform.
Your answer
Follow this Question
Related Questions
Dynamic Material & Textures 1 Answer
Problems setting parent of instantiated objects 2 Answers
Parenting an instantiated Prefab? 1 Answer
Changing game object based on variable state? 1 Answer
how Load Prefabs after build 0 Answers