using System.Collections; using System.Collections.Generic; using System.Linq; using UnityEngine; using UnityUtils; public class RopeSounding : MonoBehaviour { [SerializeField] private float PlayTime = 1f; RopeSimulator rope; AudioSource AS; float playTimeLeft = 0; // Update is called once per frame void Update() { if (rope == null) { if (TryGetComponent(out rope)) { } } if (AS == null) { TryGetComponent(out AS); AS.Play(); AS.Pause(); } if (rope.Overshoot >= 0.5f) { Vector3 soundPos = rope.rope.points.Select(x => x.position).ToList().Mean(); AS.transform.position = soundPos; AS.UnPause(); } else { // Pause AS.Pause(); } } }