51 lines
1.6 KiB
C#
51 lines
1.6 KiB
C#
using System;
|
|
using UnityEngine;
|
|
|
|
using RR.Game2D.Behaviour;
|
|
using RR.Game2D.Behaviour.ScriptableObjects;
|
|
using RR.Game2D.Core.Managers;
|
|
|
|
public class EnemyAnimationEvents : MonoBehaviour
|
|
{
|
|
private SFXAsset _stepSounds;
|
|
private SFXAsset _hurtSounds;
|
|
|
|
private void Awake()
|
|
{
|
|
EnemyController controller = GetComponent<EnemyController>();
|
|
_stepSounds = controller.sfxAsset.stepSounds;
|
|
_hurtSounds = controller.sfxAsset.hurtSounds;
|
|
}
|
|
|
|
public void OnDeathBegin()
|
|
{
|
|
// Проигрывание SFX для получения урона
|
|
if (_hurtSounds && _hurtSounds.soundEffects.Length > 0)
|
|
GameManager.Instance.Audio.PlayRandomSfxAt(_hurtSounds.soundEffects, transform.position);
|
|
|
|
gameObject.layer = LayerMask.NameToLayer("No Collision");
|
|
Rigidbody2D rb = GetComponent<Rigidbody2D>();
|
|
Collider2D col = GetComponent<Collider2D>();
|
|
EnemyController controller = GetComponent<EnemyController>();
|
|
EnemyFireScript fireScript = GetComponent<EnemyFireScript>();
|
|
if (controller) controller.enabled = false;
|
|
if (fireScript) fireScript.enabled = false;
|
|
if (col) col.enabled = false;
|
|
if (!rb) return;
|
|
rb.linearVelocity = Vector2.zero;
|
|
rb.bodyType = RigidbodyType2D.Kinematic;
|
|
}
|
|
|
|
public void OnDeathEnd()
|
|
{
|
|
Destroy(gameObject);
|
|
}
|
|
|
|
public void Step()
|
|
{
|
|
// Проигрывание SFX для шага
|
|
if (_stepSounds && _stepSounds.soundEffects.Length > 0)
|
|
GameManager.Instance.Audio.PlayRandomSfxAt(_stepSounds.soundEffects, transform.position);
|
|
}
|
|
}
|