public static void CreateNotes() { Xylophone xylophone = FindObjectOfType <Xylophone>(); List <Note> notes = new List <Note>(); List <GameObject> objectsToDestroy = new List <GameObject>(); foreach (Note existingNote in xylophone.notes) { objectsToDestroy.Add(existingNote.gameObject); } foreach (Transform noteTransform in xylophone.notesTransforms) { GameObject newNoteGo = (GameObject)PrefabUtility.InstantiatePrefab(xylophone.notePrefab); newNoteGo.transform.parent = xylophone.noteParent; newNoteGo.transform.position = noteTransform.position; newNoteGo.transform.rotation = noteTransform.rotation; newNoteGo.name = "Note " + notes.Count.ToString(); Note note = newNoteGo.GetComponent <Note>(); notes.Add(note); } foreach (GameObject objectToDestroy in objectsToDestroy) { GameObject.DestroyImmediate(objectToDestroy); } xylophone.notes = notes.ToArray(); }
public static void RandomizeXylophoneNotes() { Xylophone xylophone = FindObjectOfType <Xylophone>(); }