public class GitaraTrunb : UdonSharpBehaviour { [SerializeField] private AudioSource[] introAS; [SerializeField] private AudioSource[] firstAccordAS; [SerializeField] private AudioSource[] secondAccordAS; [SerializeField] private AudioSource[] thirdAccordAS; [SerializeField] private AudioSource[] fourthAccordAS; [SerializeField] private VRCObjectSync mediator; [SerializeField] private float maxDistance = 1.0f; private float distance = 0f; //отсчет аккордов private bool isIntro = true; private byte repeat = 0; private byte accord = 0; private byte noteCount = 0; private byte introRepeats = 0; //таймер private bool timerWork = false; [SerializeField] private float timerDelay = 3f; private float time; public void OnTriggerEnter(Collider other) { if (other.name == "Mediator") { GuitarPlay(); } } private void GuitarPlay() { if (timerWork == false) { StartTimer(); } else { RestartTimer(); } if (isIntro == true) { introAS[noteCount].Play(); noteCount++; if (noteCount > 3) { noteCount = 0; introRepeats++; } if (introRepeats > 7) { isIntro = false; introRepeats = 0; noteCount = 0; } } else { switch (accord) { case 0: firstAccordAS[noteCount].Play(); noteCount++; if (noteCount > 7) { repeat++; noteCount = 0; } if (repeat > 1) { repeat = 0; accord++; } break; case 1: secondAccordAS[noteCount].Play(); noteCount++; if (noteCount > 7) { repeat++; noteCount = 0; } if (repeat > 1) { repeat = 0; accord++; } break; case 2: thirdAccordAS[noteCount].Play(); noteCount++; if (noteCount > 7) { repeat++; noteCount = 0; } if (repeat > 1) { repeat = 0; accord++; } break; case 3: fourthAccordAS[noteCount].Play(); noteCount++; if (noteCount > 7) { repeat++; noteCount = 0; } if (repeat > 1) { repeat = 0; accord = 0; } break; default: break; } } } private void StartTimer() { timerWork = true; } private void RestartTimer() { time = timerDelay; } private void Timer() { if (timerWork == true) { time -= Time.deltaTime; if (time < 0) { isIntro = true; repeat = accord = noteCount = introRepeats = 0; timerWork= false; time = timerDelay; } } } private void Update() { distance = Vector3.Distance(this.transform.position, mediator.transform.position); if (distance > maxDistance) { mediator.transform.position = this.transform.position + new Vector3(0, 0.5f, 0); } Timer(); } }