65 lines
1.5 KiB
C#
65 lines
1.5 KiB
C#
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;
|
|
}
|
|
}
|