First we create a cube, then we create a material ball for cube, and the color of the material ball is red. The color of the material ball to the cube,cube turns red.
Create an empty object (gameobject) named Container, as the name implies, this will be used as a container.
To write a script:
Using Unityengine;
Using System.Collections;
public class Giveparent:monobehaviour {public
gameobject prefab;
Use the this for initialization
void Start () {
Gameobject container = gameobject.find ("container");
The first kind of
//gameobject prefabinstance = Instantiate (prefab);
PrefabInstance.transform.parent = Container.transform;
The second type of
gameobject PFB = resources.load ("Prefabs/cube") as Gameobject;
Gameobject prefabinstance = Instantiate (PFB);
PrefabInstance.transform.parent = Container.transform;
}
Update is called once per frame
void Update () {
}
}
The second is what I added later: The Prefab Cube was later placed under the Resource/prefabs directory
Scripts are mounted on container
Drag and drop the finished preform here
To run the program: