Danil Iarosh 5bafc385da feat(audio): increase SFX pool size and preload audio data
- Increased SFX pool size from 8 to 16 in AudioManager
- Enabled preloadAudioData for multiple SFX files
- Removed unused VisualScripting import from Checkpoint script
- Reordered using statements in several scripts for consistency
- Added CoinCollectible component to Coin prefab with pickup effects
- Updated sorting layers and mesh LOD settings in Coin prefabs
- Fixed typo in Interfaces.cs: optionaAttachPoint to optionalAttachPoint
- Modified AddCoin method to accept count parameter and handle coin overflow
- Moved projectile scripts (BasicProjectile, EnemyBasicProjectile, PhysicsProjectile, PickableProjectile)
- Cleaned up unused namespaces and imports across various scripts
2025-10-30 16:39:15 +03:00

93 lines
3.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 UnityEngine.InputSystem;
using RR.Game2D.Core.Managers;
using RR.Game2D.Behaviour.ScriptableObjects;
using RR.Game2D.Entities.Projectiles;
namespace RR.Game2D.Behaviour
{
[RequireComponent(typeof(Collider2D))]
public class PlayerFireScript : MonoBehaviour
{
[Header("Управление")]
[SerializeField] private InputActionReference fireButton;
[Header("Снаряд")]
[SerializeField] private PickableProjectile projectilePrefab;
public bool spawnIfMissing = false;
[Header("Бросок / Подбор")]
[SerializeField] private float throwSpeed = 20f;
[SerializeField] private Vector2 launchAxis;
[SerializeField] private Transform launchPoint;
[SerializeField] public Transform attachPoint;
[Header("FX")]
[SerializeField] private SFXAsset throwSounds;
private PickableProjectile _pickableProjectile;
private Collider2D _col;
void Awake()
{
if (!attachPoint)
Debug.LogWarning("PlayerFireScript: attachPoint не задан. Будет использован корень игрока.");
_col = GetComponent<Collider2D>();
}
void Update()
{
//if (!Input.GetButtonDown("Fire1")) return;
if (!fireButton.action.WasPressedThisFrame()) return;
if (_pickableProjectile == null)
_pickableProjectile = PickableProjectile.Instance;
if (_pickableProjectile == null)
{
if (!spawnIfMissing || projectilePrefab == null)
{
Debug.LogError("PlayerFireScript: projectile missing; enable spawnIfMissing and assign projectilePrefab.");
return;
}
Vector3 spawnPos = attachPoint ? attachPoint.position : transform.position;
_pickableProjectile = Instantiate(projectilePrefab, spawnPos, Quaternion.identity);
_pickableProjectile.TryPickup(gameObject, attachPoint);
return;
}
// Бросок
if (_pickableProjectile.CurrentState == PickableProjectile.State.Held && _pickableProjectile.owner == gameObject) Throw();
}
/// <summary>
/// Метод для броска снаряда (выстрела).
/// У снаряда обязательно должен быть метод Launch(Vector2 direction)
/// </summary>
private void Throw()
{
launchAxis = launchAxis.normalized;
float facing = Mathf.Abs(transform.localEulerAngles.y) >= 180 ? -1 : 1;
Vector2 directionX = facing > 0 ? Vector2.right : Vector2.left;
Vector2 launchPos = new (1.4f * facing + launchPoint.position.x, launchPoint.position.y);
//Debug.Log(col.bounds.center.y);
launchAxis.x = launchAxis.x == 0 ? launchAxis.x : directionX.x;
if (throwSounds.soundEffects.Length > 0)
GameManager.Instance.Audio.PlayRandomSfxAt(throwSounds.soundEffects, transform.position);
Vector3 projectileScale = _pickableProjectile.transform.localScale;
_pickableProjectile.transform.localScale = new Vector3(Mathf.Abs(projectileScale.x) * -facing, projectileScale.y, projectileScale.z);
_pickableProjectile.transform.position = launchPos;
_pickableProjectile.Launch(launchAxis, throwSpeed, gameObject);
}
/// <summary>
/// Метод для привязки снаряда к игроку.
/// </summary>
/// <param name="proj">Снаряд</param>
public void BindProjectile(PickableProjectile proj) => _pickableProjectile = proj;
}
}