void CreateFromFile() { GameObject NewObject; for (int i = 0; i < level.editorObjects.Count; i++) { if (level.editorObjects[i].objectType == EditorObject.ObjectType.Platform) { NewObject = Instantiate(Platform, level.editorObjects[i].pos, Quaternion.identity); NewObject.layer = 9; EditorObject eo = NewObject.AddComponent <EditorObject>(); eo.data.pos = NewObject.transform.position; eo.data.objectType = EditorObject.ObjectType.Platform; } else if (level.editorObjects[i].objectType == EditorObject.ObjectType.Coin) { NewObject = Instantiate(Coin, level.editorObjects[i].pos, Quaternion.identity); NewObject.layer = 9; EditorObject eo = NewObject.AddComponent <EditorObject>(); eo.data.pos = NewObject.transform.position; eo.data.objectType = EditorObject.ObjectType.Coin; } else if (level.editorObjects[i].objectType == EditorObject.ObjectType.Player) { NewObject = Instantiate(Player, level.editorObjects[i].pos, Quaternion.identity); NewObject.layer = 9; // set to Spawned Objects layer PlayerPlaced = true; EditorObject eo = NewObject.AddComponent <EditorObject>(); eo.data.pos = NewObject.transform.position; eo.data.objectType = EditorObject.ObjectType.Player; } else if (level.editorObjects[i].objectType == EditorObject.ObjectType.StartPos) { NewObject = Instantiate(StartPos, level.editorObjects[i].pos, Quaternion.identity); NewObject.layer = 9; // set to Spawned Objects layer StartpointPresent = true; EditorObject eo = NewObject.AddComponent <EditorObject>(); eo.data.pos = NewObject.transform.position; eo.data.objectType = EditorObject.ObjectType.StartPos; } else if (level.editorObjects[i].objectType == EditorObject.ObjectType.EndPos) { NewObject = Instantiate(EndPos, level.editorObjects[i].pos, Quaternion.identity); NewObject.layer = 9; // set to Spawned Objects layer EndPointPlaced = true; EditorObject eo = NewObject.AddComponent <EditorObject>(); eo.data.pos = NewObject.transform.position; eo.data.objectType = EditorObject.ObjectType.EndPos; } } LoadlevelName.text = ""; LoadlevelName.DeactivateInputField(); SaveLoadMessage.text = " Level Loading done"; }
void CreateObject() { GameObject NewObject; if (itemOption == ItemList.Platform) { NewObject = Instantiate(Platform, transform.position, Quaternion.identity); NewObject.layer = 9; EditorObject eo = NewObject.AddComponent <EditorObject>(); eo.data.pos = NewObject.transform.position; eo.data.objectType = EditorObject.ObjectType.Platform; } else if (itemOption == ItemList.Coin) { NewObject = Instantiate(Coin, transform.position, Quaternion.identity); NewObject.layer = 9; EditorObject eo = NewObject.AddComponent <EditorObject>(); eo.data.pos = NewObject.transform.position; eo.data.objectType = EditorObject.ObjectType.Coin; } else if (itemOption == ItemList.Player) { if (ms.StartpointPresent && ms.PlayerPlaced == false) { NewObject = Instantiate(Player, GameObject.FindGameObjectWithTag("Starting").transform.position, Quaternion.identity); NewObject.layer = 9; ms.spriteRenderer.sprite = null; ms.PlayerPlaced = true; EditorObject eo = NewObject.AddComponent <EditorObject>(); eo.data.pos = NewObject.transform.position; eo.data.objectType = EditorObject.ObjectType.Player; } else if (ms.StartpointPresent == false) { ms.MessagePopup.SetActive(true); } } else if (itemOption == ItemList.StartPos) { if (ms.StartpointPresent == false) { NewObject = Instantiate(StartPos, transform.position, Quaternion.identity); NewObject.layer = 9; ms.StartpointPresent = true; EditorObject eo = NewObject.AddComponent <EditorObject>(); eo.data.pos = NewObject.transform.position; eo.data.objectType = EditorObject.ObjectType.StartPos; } } else if (itemOption == ItemList.EndPos) { if (ms.EndPointPlaced == false) { NewObject = Instantiate(EndPos, transform.position, Quaternion.identity); NewObject.layer = 9; ms.EndPointPlaced = true; EditorObject eo = NewObject.AddComponent <EditorObject>(); eo.data.pos = NewObject.transform.position; eo.data.objectType = EditorObject.ObjectType.EndPos; } } }