private static void CreatePrefab(string path, MiniMap sourceMap, string spritePath) { GameObject go = new GameObject(); var minimap = go.AddComponent <MiniMap> (); minimap.position = sourceMap.position; minimap.direction = sourceMap.direction; minimap.mapId = sourceMap.mapId; var camera = go.AddComponent <Camera> (); camera.CopyFrom(sourceMap.GetComponent <Camera>()); camera.cullingMask = 0; camera.clearFlags = CameraClearFlags.Nothing; var renderer = go.AddComponent <SpriteRenderer> (); var sprite = AssetDatabase.LoadAssetAtPath <Sprite> (spritePath); renderer.sprite = sprite; PrefabUtility.CreatePrefab(path, go); GameObject.DestroyImmediate(go); }