среда, 11 декабря 2013 г.

Unity 3D - How to get Prefab by Name

To get prefab at Runtime use follow code:

GameObject prefabBullet = (GameObject) Resources.LoadAssetAtPath("Assets/Prefabs/Bullet.prefab", typeof(GameObject));

The same way, you can load any resources type:

Texture2D texture = (Texture2D) Resources.LoadAssetAtPath("Assets/Textures/texture.png", typeof(Texture2D));