2024-02-04 04:03:19 +01:00
|
|
|
using System.Collections;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Linq;
|
|
|
|
using UnityEngine;
|
|
|
|
using UnityUtils;
|
|
|
|
|
|
|
|
public class RopeSounding : MonoBehaviour
|
|
|
|
{
|
|
|
|
[SerializeField] private float PlayTime = 1f;
|
|
|
|
|
2024-05-26 21:15:38 +02:00
|
|
|
RopeSimulatorOld rope;
|
2024-02-04 04:03:19 +01:00
|
|
|
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
}
|
2024-05-26 21:15:38 +02:00
|
|
|
}
|