Working MVP
This commit is contained in:
@@ -102,6 +102,14 @@ namespace Minigames.FortFight.Fort
|
||||
/// </summary>
|
||||
public void Initialize()
|
||||
{
|
||||
// Automatically assign block to correct layer from settings
|
||||
var settings = CachedSettings;
|
||||
if (settings != null && settings.FortBlockLayer >= 0 && gameObject.layer != settings.FortBlockLayer)
|
||||
{
|
||||
gameObject.layer = settings.FortBlockLayer;
|
||||
Logging.Debug($"[FortBlock] Assigned {gameObject.name} to layer {LayerMask.LayerToName(settings.FortBlockLayer)}");
|
||||
}
|
||||
|
||||
// Cache components
|
||||
rb2D = GetComponent<Rigidbody2D>();
|
||||
blockCollider = GetComponent<Collider2D>();
|
||||
@@ -260,7 +268,10 @@ namespace Minigames.FortFight.Fort
|
||||
{
|
||||
Logging.Debug($"[FortBlock] Spawning explosion effect prefab");
|
||||
GameObject explosion = Instantiate(explosionEffectPrefab, transform.position, Quaternion.identity);
|
||||
Destroy(explosion, 3f); // Auto-cleanup after 3 seconds
|
||||
|
||||
// Dynamically determine cleanup time from particle system
|
||||
float lifetime = GetEffectLifetime(explosion);
|
||||
Destroy(explosion, lifetime);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -360,6 +371,30 @@ namespace Minigames.FortFight.Fort
|
||||
Logging.Debug($"[FortBlock] Spawning destruction effect for {material} block");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get the lifetime of an effect by reading particle system StartLifetime.
|
||||
/// Falls back to 3 seconds if no particle system found.
|
||||
/// </summary>
|
||||
private float GetEffectLifetime(GameObject effect)
|
||||
{
|
||||
// Try to read from ParticleSystem
|
||||
ParticleSystem ps = effect.GetComponent<ParticleSystem>();
|
||||
if (ps != null)
|
||||
{
|
||||
return ps.main.startLifetime.constantMax + 0.5f; // Add small buffer
|
||||
}
|
||||
|
||||
// Try to read from child particle systems
|
||||
ParticleSystem childPs = effect.GetComponentInChildren<ParticleSystem>();
|
||||
if (childPs != null)
|
||||
{
|
||||
return childPs.main.startLifetime.constantMax + 0.5f;
|
||||
}
|
||||
|
||||
// Fallback for non-particle effects
|
||||
return 3f;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Debug Helpers
|
||||
|
||||
Reference in New Issue
Block a user