photo_input_switch (#27)

Co-authored-by: Michal Pikulski <michal.a.pikulski@gmail.com>
Reviewed-on: #27
This commit is contained in:
2025-10-14 07:09:16 +00:00
parent 2573e7f80e
commit 9c44a0c91f
8 changed files with 174 additions and 20 deletions

View File

@@ -29,6 +29,8 @@ namespace Minigames.DivingForPictures
private void Awake()
{
Debug.Log("Monster created: " + gameObject.name);
if (detectionCollider == null)
detectionCollider = GetComponent<CircleCollider2D>();
@@ -44,6 +46,11 @@ namespace Minigames.DivingForPictures
photoSequenceInProgress = false;
}
private void OnDestroy()
{
Debug.Log("Monster destroyed: " + gameObject.name);
}
private IEnumerator CheckIfOffScreen()
{
WaitForSeconds wait = new WaitForSeconds(0.5f);
@@ -72,15 +79,24 @@ namespace Minigames.DivingForPictures
Vector3 worldPosition = transform.position;
Vector3 viewportPoint = mainCamera.WorldToViewportPoint(worldPosition);
// Adjust buffer to be larger below the screen to account for downward movement
float bufferSides = 0.2f;
float bufferTop = 0.2f;
float bufferBottom = 0.5f; // Larger buffer below the screen
// If z is negative, the object is behind the camera
if (viewportPoint.z < 0)
return false;
return viewportPoint.x > -bufferSides &&
viewportPoint.x < 1 + bufferSides &&
viewportPoint.y > -bufferBottom &&
viewportPoint.y < 1 + bufferTop;
// Simple logic:
// 1. Allow monsters below the screen (new spawns)
// 2. Despawn monsters only when completely above the top of screen
// 3. Keep monsters that are on screen
// Check if the monster is above the top of the screen
if (viewportPoint.y > 1)
return false; // Monster is completely above screen, destroy it
// Check horizontal bounds (keep moderate buffer so monsters don't disappear at screen edges)
float bufferSides = 0.2f;
bool withinHorizontalBounds = viewportPoint.x > -bufferSides && viewportPoint.x < 1 + bufferSides;
return withinHorizontalBounds;
}
private void OnTriggerEnter2D(Collider2D other)