diff --git a/Assets/Editor/TrenchTileSpawnerEditor.cs b/Assets/Editor/TrenchTileSpawnerEditor.cs
new file mode 100644
index 00000000..1178e8ad
--- /dev/null
+++ b/Assets/Editor/TrenchTileSpawnerEditor.cs
@@ -0,0 +1,42 @@
+using UnityEditor;
+using UnityEngine;
+using Minigames.DivingForPictures;
+
+///
+/// Custom editor for TrenchTileSpawner that adds a runtime button to test the StartSurfacing function
+///
+[CustomEditor(typeof(TrenchTileSpawner))]
+public class TrenchTileSpawnerEditor : UnityEditor.Editor
+{
+ public override void OnInspectorGUI()
+ {
+ // Draw the default inspector
+ DrawDefaultInspector();
+
+ // Get the target TrenchTileSpawner
+ TrenchTileSpawner spawner = (TrenchTileSpawner)target;
+
+ // Add space between default inspector and custom button
+ EditorGUILayout.Space(10);
+
+ // Separator line
+ EditorGUILayout.LabelField("", GUI.skin.horizontalSlider);
+
+ // Add a label for the runtime testing section
+ EditorGUILayout.LabelField("Runtime Testing", EditorStyles.boldLabel);
+
+ // Only enable the button during play mode
+ EditorGUI.BeginDisabledGroup(!Application.isPlaying);
+
+ // Add the button to call StartSurfacing
+ if (GUILayout.Button("Start Surfacing", GUILayout.Height(30)))
+ {
+ spawner.StartSurfacing();
+ }
+
+ EditorGUI.EndDisabledGroup();
+
+ // Add explanatory text
+ EditorGUILayout.HelpBox("This button will reverse the direction of the trench movement, making the player surface instead of descend. Only works in Play Mode.", MessageType.Info);
+ }
+}
diff --git a/Assets/Editor/TrenchTileSpawnerEditor.cs.meta b/Assets/Editor/TrenchTileSpawnerEditor.cs.meta
new file mode 100644
index 00000000..99db4891
--- /dev/null
+++ b/Assets/Editor/TrenchTileSpawnerEditor.cs.meta
@@ -0,0 +1,3 @@
+fileFormatVersion: 2
+guid: 9fb1a138e45d4720ba5c95da894b4491
+timeCreated: 1758531024
\ No newline at end of file
diff --git a/Assets/Scripts/Minigames/DivingForPictures/TrenchTileSpawner.cs b/Assets/Scripts/Minigames/DivingForPictures/TrenchTileSpawner.cs
index 28789276..e436b914 100644
--- a/Assets/Scripts/Minigames/DivingForPictures/TrenchTileSpawner.cs
+++ b/Assets/Scripts/Minigames/DivingForPictures/TrenchTileSpawner.cs
@@ -59,6 +59,9 @@ namespace Minigames.DivingForPictures
private const float TileSpawnZ = -1f;
private const float DefaultTileHeight = 5f;
+ // Direction state
+ private bool _isSurfacing = false;
+
private void Awake()
{
_mainCamera = Camera.main;
@@ -270,6 +273,26 @@ namespace Minigames.DivingForPictures
_screenTop = top.y;
}
+ ///
+ /// Reverses direction to start surfacing
+ ///
+ public void StartSurfacing()
+ {
+ if (_isSurfacing) return; // Already surfacing
+
+ // Reverse the movement direction
+ moveSpeed *= -1;
+
+ // Update velocity immediately
+ CalculateVelocity();
+
+ // Reverse the active tiles array to maintain consistent indexing logic
+ _activeTiles.Reverse();
+
+ // Set surfacing flag
+ _isSurfacing = true;
+ }
+
///
/// Handles the movement of all active tiles based on the current velocity
///
@@ -279,6 +302,7 @@ namespace Minigames.DivingForPictures
{
if (tile != null)
{
+ // Movement will automatically adapt to negative velocity when surfacing
tile.transform.position += Vector3.up * _currentVelocity;
}
}
@@ -299,7 +323,20 @@ namespace Minigames.DivingForPictures
}
float tileHeight = GetTileHeight(topTile);
- if (topTile.transform.position.y - tileHeight / 2 > _screenTop + tileSpawnBuffer)
+
+ bool shouldDestroy;
+ if (_isSurfacing)
+ {
+ // When surfacing, destroy tiles at the bottom
+ shouldDestroy = topTile.transform.position.y + tileHeight / 2 < _screenBottom - tileSpawnBuffer;
+ }
+ else
+ {
+ // When descending, destroy tiles at the top
+ shouldDestroy = topTile.transform.position.y - tileHeight / 2 > _screenTop + tileSpawnBuffer;
+ }
+
+ if (shouldDestroy)
{
_activeTiles.RemoveAt(0);
onTileDestroyed?.Invoke(topTile);
@@ -339,14 +376,31 @@ namespace Minigames.DivingForPictures
}
float tileHeight = GetTileHeight(bottomTile);
- float bottomEdge = bottomTile.transform.position.y - tileHeight / 2;
- if (bottomEdge > _screenBottom - tileSpawnBuffer)
+
+ bool shouldSpawn;
+ float newY;
+
+ if (_isSurfacing)
+ {
+ // When surfacing, spawn new tiles at the top
+ float topEdge = bottomTile.transform.position.y + tileHeight / 2;
+ shouldSpawn = topEdge < _screenTop + tileSpawnBuffer;
+ newY = bottomTile.transform.position.y + tileHeight;
+ }
+ else
+ {
+ // When descending, spawn new tiles at the bottom
+ float bottomEdge = bottomTile.transform.position.y - tileHeight / 2;
+ shouldSpawn = bottomEdge > _screenBottom - tileSpawnBuffer;
+ newY = bottomTile.transform.position.y - tileHeight;
+ }
+
+ if (shouldSpawn)
{
- float newY = bottomTile.transform.position.y - tileHeight;
SpawnTileAtY(newY);
}
}
-
+
///
/// Handle increasing the movement speed over time
///