Danil Iarosh a845161079 feat(audio): Integrated level-specific sound effects and music control
-Add LevelSpecificPlayerSFX prefabs for levels 1-1 and 1-2
-Configure checkpoints to activate sound effects, including pitch, volume, and audio editing
-Rename the checkpoint effect object to Checkpoint VFX
-Update the audio manager, the default value of the music target volume is 0.2
-Add SoundEffect structure to support sound parameter configuration
-Optimize audio source creation and crossfade logic
-Remove the old music control components and use the new audio management method
2025-10-29 16:46:24 +03:00

75 lines
2.8 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using UnityEngine;
using RR.Game2D.Core.Managers;
using RR.Game2D.Entities.Projectiles;
using RR.Game2D.Behaviour.ScriptableObjects;
namespace RR.Game2D.Behaviour
{
public class EnemyFireScript : MonoBehaviour
{
[SerializeField] private EnemyFireConfiguration config;
private float lastThrowTime = -999f;
private EnemyBasicProjectile _projectile;
void Start()
{
lastThrowTime = Time.time;
}
void Update()
{
if (!config.projectilePrefab)
{
Debug.LogError("EnemyFireScript: projectile prefab missing; assign projectile prefab in the inspector");
return;
}
//if (projectile != null && Time.time - lastThrowTime >= projectile.maxLifetime)
// projectile.Despawn();
// Бросок
if (Time.time - lastThrowTime >= config.throwCooldown)
Throw();
}
private void OnDestroy()
{
// При смерти врага сго снаряд тоже пропадает
if (_projectile != null) _projectile.Despawn();
}
/// <summary>
/// Метод для броска снаряда (выстрела).
/// У снаряда обязательно должен быть метод Launch(Vector2 direction)
/// </summary>
private void Throw()
{
float rotationY = transform.localEulerAngles.y;
Vector2 throwDirection = rotationY >= 180f ? Vector2.right : Vector2.left;
Collider2D enemyCol = GetComponent<Collider2D>();
Vector2 throwPosition = new(1.4f * throwDirection.x + transform.position.x, enemyCol.bounds.center.y);
_projectile = Instantiate(config.projectilePrefab, throwPosition, Quaternion.identity);
_projectile.owner = gameObject;
_projectile.maxLifetime = config.projectileLifetime;
_projectile.despawnInstantly = config.projectileDespawnInstantly;
_projectile.fallGravityScale = config.projectileFallGravityScale;
Collider2D projectileCol = _projectile.GetComponent<Collider2D>();
_projectile.transform.localRotation = throwDirection.x < 0 ? Quaternion.Inverse(_projectile.transform.localRotation) : _projectile.transform.localRotation;
_projectile.transform.position = throwPosition;
_projectile.Launch(throwDirection, config.throwSpeed);
if (config.shotSounds.Length > 0)
GameManager.Instance.Audio.PlayRandomSfxAt(config.shotSounds, throwPosition);
if (enemyCol && projectileCol) Physics2D.IgnoreCollision(enemyCol, projectileCol, true);
lastThrowTime = Time.time;
}
}
}