Danro/Assets/Scripts/FX/PlayerRunVFX.cs
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

72 lines
3.0 KiB
C#

using UnityEngine;
using UnityEngine.VFX;
using RR.Game2D.Behaviour;
using RR.Game2D.Core.Managers;
namespace RR.Game2D.FX
{
[RequireComponent(typeof(VisualEffect))]
public class PlayerRunVFX : MonoBehaviour
{
[SerializeField] private VisualEffect runVFX;
[SerializeField] private Vector2 offset = Vector2.zero;
[SerializeField] private float requiredPlayerRunTime;
private GameObject _player;
private Rigidbody2D _playerRB;
private PlayerController _playerController;
private float _startRunTime = 0;
private Vector3 particlesVelocityDirection;
// Start is called once before the first execution of Update after the MonoBehaviour is created
void Start()
{
_player = GameManager.Instance.PlayerObj;
_playerRB = _player.GetComponent<Rigidbody2D>();
_playerController = _player.GetComponent<PlayerController>();
if (_player == null) _player = GameObject.FindGameObjectWithTag("Player");
particlesVelocityDirection = runVFX.GetVector3("ParticlesVelocityDirection");
runVFX.Stop();
// runVFX.enabled = false;
}
// Update is called once per frame
void Update()
{
if (_playerController.IsGrounded) transform.position = _player.transform.position
+ new Vector3(offset.x * Mathf.Sign(_playerRB.linearVelocityX), offset.y, 0f);
else transform.position = new Vector3(_player.transform.position.x, transform.position.y, transform.position.z);
if (!runVFX.enabled) runVFX.enabled = true;
if (Mathf.Abs(_playerRB.linearVelocityX) >= 0.01f && _playerController.IsGrounded)
{
if (_startRunTime == 0) _startRunTime = Time.time;
if (Time.time - _startRunTime < requiredPlayerRunTime) return;
runVFX.Play();
runVFX.SetVector3("ParticlesVelocityDirection", new Vector3(particlesVelocityDirection.x * Mathf.Sign(_playerRB.linearVelocityX),
particlesVelocityDirection.y,
particlesVelocityDirection.z));
return;
}
if (_playerRB.linearVelocityY >= 0.25f * _playerController.jumpVelocity)
{
runVFX.SetVector3("ParticlesVelocityDirection", new Vector3(particlesVelocityDirection.x * Mathf.Sign(_playerRB.linearVelocityX),
_playerRB.linearVelocityY,
particlesVelocityDirection.z));
runVFX.Play();
if (_playerRB.linearVelocityX == 0) _startRunTime = 0;
return;
}
_startRunTime = 0;
runVFX.Stop();
}
}
}