using CartoonFX; using System.Collections; using UnityEngine; public class BoxingMachine : MonoBehaviour { public Transform punchBag; // груша public float punchAngle = 90f; // на сколько градусов махать public float punchDuration = 0.2f; // время движения туда и обратно public Transform hitPoint; [Header("UI/FX")] [SerializeField] private ParticleSystem ps; private Quaternion startRotation; private void Awake() { if (punchBag != null) startRotation = punchBag.localRotation; } public void Hit() { // анимация груши if (punchBag != null) StartCoroutine(PunchCoroutine()); if (ps != null) { ps.Play(); } } private IEnumerator PunchCoroutine() { Quaternion targetRot = startRotation * Quaternion.Euler(0, 0, punchAngle); float elapsed = 0f; // мах вперед while (elapsed < punchDuration) { punchBag.localRotation = Quaternion.Slerp(startRotation, targetRot, elapsed / punchDuration); elapsed += Time.deltaTime; yield return null; } punchBag.localRotation = targetRot; // мах назад elapsed = 0f; while (elapsed < punchDuration) { punchBag.localRotation = Quaternion.Slerp(targetRot, startRotation, elapsed / punchDuration); elapsed += Time.deltaTime; yield return null; } punchBag.localRotation = startRotation; } }