Surfacing functions in all manager components

This commit is contained in:
2025-09-22 11:40:01 +02:00
parent bb3c91ec94
commit b0e44f156e
6 changed files with 226 additions and 16 deletions

View File

@@ -44,8 +44,10 @@ namespace Minigames.DivingForPictures
private Collider2D _collider;
private Camera _mainCamera;
private float _screenTop;
private float _screenBottom; // Added to track bottom of screen
private Coroutine _movementCoroutine;
private Coroutine _offScreenCheckCoroutine;
private bool _isSurfacing = false; // Flag to track surfacing state
private void Awake()
{
@@ -165,6 +167,9 @@ namespace Minigames.DivingForPictures
Vector3 topWorldPoint = _mainCamera.ViewportToWorldPoint(new Vector3(0.5f, 1f, _mainCamera.transform.position.z));
_screenTop = topWorldPoint.y;
Vector3 bottomWorldPoint = _mainCamera.ViewportToWorldPoint(new Vector3(0.5f, 0f, _mainCamera.transform.position.z));
_screenBottom = bottomWorldPoint.y;
// Check if obstacle is significantly above screen top (obstacles move upward)
// Use a larger buffer to ensure obstacles are truly off-screen before returning to pool
if (transform.position.y > _screenTop + 5f)
@@ -172,6 +177,11 @@ namespace Minigames.DivingForPictures
Debug.Log($"[FloatingObstacle] {gameObject.name} off-screen at Y:{transform.position.y:F2}, screen top:{_screenTop:F2}");
ReturnToPool();
}
else if (transform.position.y < _screenBottom - 5f) // Added check for bottom screen edge
{
Debug.Log($"[FloatingObstacle] {gameObject.name} below screen at Y:{transform.position.y:F2}, screen bottom:{_screenBottom:F2}");
ReturnToPool();
}
}
/// <summary>
@@ -279,5 +289,20 @@ namespace Minigames.DivingForPictures
StartObstacleBehavior();
}
}
/// <summary>
/// Sets surfacing mode, which reverses obstacle movement direction
/// </summary>
public void StartSurfacing()
{
if (_isSurfacing) return; // Already surfacing
_isSurfacing = true;
// Reverse movement speed (already handled by ObstacleSpawner, but this ensures consistency)
moveSpeed *= -1;
Debug.Log($"[FloatingObstacle] {gameObject.name} started surfacing with speed: {moveSpeed}");
}
}
}