Skip to content

Instantly share code, notes, and snippets.

@xanathar
Created September 17, 2015 17:32
Show Gist options
  • Save xanathar/4680ec3e680c1ee37102 to your computer and use it in GitHub Desktop.
Save xanathar/4680ec3e680c1ee37102 to your computer and use it in GitHub Desktop.
Instantiate Prefab By Name
using UnityEngine;
using System.Collections;
public class LevelCloner : MonoBehaviour
{
// Use this for initialization
void Start ()
{
Debug.Log ("Enter!");
// prefab must be under Assets/Resources <- important!!
object o = Resources.Load ("Dungeon_Kit/Prefabs/Dungeon_Floors_Walls/floor_tile_01");
Debug.Log (o.ToString ());
var floorPrefab = o as GameObject;
for (int y = 0; y < 5; y++)
{
for (int x = 0; x < 5; x++)
{
GameObject floor = Instantiate (floorPrefab);
// floor.AddComponent<Rigidbody> ();
floor.transform.position = new Vector3 (x, 0, y);
}
}
}
// Update is called once per frame
void Update ()
{
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment