// Use this for initialization protected override void OnStart() { generator = GetComponent <WaveGenerator>(); Player = GetComponent <Instrument> (); uint octave = (uint)Random.Range(LowLevel, HighLevel); List <MelodyTansitionInfo> transitions = new List <MelodyTansitionInfo>(); List <Note> scale = MusicGenerator.GenerateScale(BaseNote, Octave, !IsMinor); for (int i = 0; i < scale.Count; i++) { transitions.Add(new MelodyTansitionInfo(i, Random.Range(0, scale.Count), 1)); } int transitionCount = Random.Range(7, 15); for (int i = 0; i < transitionCount; i++) { transitions.Add(new MelodyTansitionInfo( Random.Range(0, scale.Count), Random.Range(0, scale.Count), Random.value * 2)); } machine = new MelodyMachine(scale, transitions); machine.SetOctave(octave); if (Repeat && PatternLength > 0) { for (int i = 0; i < PatternLength; i++) { melody.Add(machine.CurrentNote); machine.Next(); } } }