Commit 45b90dea authored by KenzyAshour2's avatar KenzyAshour2

ai better seka now

parent b9510b9b
This diff is collapsed.
......@@ -4,19 +4,19 @@ using System.Collections.Generic;
public class DeepSeaSpawner : MonoBehaviour
{
[Header("Game Logic")]
public Button nextButton;
[SerializeField] SpriteRenderer zoneRenderer;
[SerializeField] Color highlightColor = new Color(0f, 1f, 0f, 0.4f);
private Color hiddenColor = new Color(0f, 0f, 0f, 0f);
[SerializeField] Button nextButton;
public int rocksNeededToWin = 3;
private int currentPlacedRocks = 0;
[Header("Bubble Settings")]
public GameObject bubblePrefab;
public Transform[] bubbleSpawnPoints;
public float bubbleInterval = 1.5f;
[SerializeField] GameObject bubblePrefab;
[SerializeField] Transform[] bubbleSpawnPoints;
[SerializeField] float bubbleInterval = 1.5f;
[Header("Floating Rock Settings")]
public GameObject[] rockPrefabs;
[SerializeField] GameObject[] rockPrefabs;
public int initialRockCount = 12;
public float spawnPadding = 0.5f;
......@@ -26,46 +26,47 @@ public class DeepSeaSpawner : MonoBehaviour
void Start()
{
cam = Camera.main;
if (zoneRenderer != null) zoneRenderer.color = hiddenColor;
}
void OnEnable()
{
if (cam == null) cam = Camera.main;
// Reset the game logic
currentPlacedRocks = 0;
// --- THE FIX ---
// We wait 0.1 seconds to make sure we override the ImageSwitcher
Invoke(nameof(LockButton), 0.1f);
// ----------------
SpawnInitialRocks();
InvokeRepeating(nameof(SpawnBubble), 0f, bubbleInterval);
}
void LockButton()
public void SetZoneHighlight(bool isActive)
{
if (nextButton != null)
if (zoneRenderer != null)
{
nextButton.interactable = false;
zoneRenderer.color = isActive ? highlightColor : hiddenColor;
}
}
void LockButton()
{
if (nextButton != null) nextButton.interactable = false;
}
void OnDisable()
{
CancelInvoke();
CleanupObjects();
if (zoneRenderer != null) zoneRenderer.color = hiddenColor;
}
public void RockPlaced()
{
currentPlacedRocks++;
SetZoneHighlight(false);
if (currentPlacedRocks >= rocksNeededToWin)
{
if (nextButton != null) nextButton.interactable = true;
Debug.Log("Deposition Complete! Next button unlocked.");
Debug.Log("Deposition Complete!");
}
}
......@@ -73,22 +74,17 @@ public class DeepSeaSpawner : MonoBehaviour
{
Vector2 minScreen = cam.ViewportToWorldPoint(new Vector3(0, 0, 0));
Vector2 maxScreen = cam.ViewportToWorldPoint(new Vector3(1, 1, 0));
float bottomLimit = minScreen.y + 2.0f;
for (int i = 0; i < initialRockCount; i++)
{
if (rockPrefabs.Length == 0) return;
GameObject randomPrefab = rockPrefabs[Random.Range(0, rockPrefabs.Length)];
float randomX = Random.Range(minScreen.x + spawnPadding, maxScreen.x - spawnPadding);
float randomY = Random.Range(bottomLimit, maxScreen.y - spawnPadding);
Vector3 spawnPos = new Vector3(randomX, randomY, 0);
GameObject rock = Instantiate(randomPrefab, spawnPos, Quaternion.identity);
GameObject rock = Instantiate(randomPrefab, new Vector3(randomX, randomY, 0), Quaternion.identity);
rock.transform.SetParent(this.transform);
spawnedObjects.Add(rock);
}
......@@ -97,11 +93,8 @@ public class DeepSeaSpawner : MonoBehaviour
void SpawnBubble()
{
if (bubblePrefab == null || bubbleSpawnPoints.Length == 0) return;
Transform spawnPoint = bubbleSpawnPoints[Random.Range(0, bubbleSpawnPoints.Length)];
Vector3 spawnPos = spawnPoint.position + new Vector3(Random.Range(-0.2f, 0.2f), 0.5f, 0);
GameObject bubble = Instantiate(bubblePrefab, spawnPos, Quaternion.identity);
GameObject bubble = Instantiate(bubblePrefab, spawnPoint.position, Quaternion.identity);
bubble.transform.SetParent(this.transform);
spawnedObjects.Add(bubble);
}
......
......@@ -7,8 +7,8 @@ public class FloatingDraggableRock : MonoBehaviour
private Vector3 targetPos;
private bool isDragging = false;
private bool isPlaced = false; // Is it stuck to the ground?
private bool isHoveringGround = false; // Are we currently over the zone?
private bool isPlaced = false;
private bool isHoveringGround = false;
private Vector3 dragOffset;
private float zCoord;
......@@ -18,46 +18,35 @@ public class FloatingDraggableRock : MonoBehaviour
void Start()
{
cam = Camera.main;
// Find the spawner so we can tell it when we are placed
mySpawner = GetComponentInParent<DeepSeaSpawner>();
PickNewScreenTarget();
}
void Update()
{
// If placed, do nothing (stay stuck)
if (isPlaced) return;
if (!isDragging)
{
// Move slowly towards the target
transform.position = Vector3.MoveTowards(transform.position, targetPos, floatSpeed * Time.deltaTime);
if (Vector3.Distance(transform.position, targetPos) < 0.1f)
{
PickNewScreenTarget();
}
if (Vector3.Distance(transform.position, targetPos) < 0.1f) PickNewScreenTarget();
}
}
void PickNewScreenTarget()
{
// Keep floating targets high up so they don't accidentally float into the ground zone
Vector2 minScreen = cam.ViewportToWorldPoint(new Vector3(0.1f, 0.3f, 0)); // Start 30% up the screen
Vector2 minScreen = cam.ViewportToWorldPoint(new Vector3(0.1f, 0.3f, 0));
Vector2 maxScreen = cam.ViewportToWorldPoint(new Vector3(0.9f, 0.9f, 0));
float x = Random.Range(minScreen.x, maxScreen.x);
float y = Random.Range(minScreen.y, maxScreen.y);
targetPos = new Vector3(x, y, transform.position.z);
targetPos = new Vector3(Random.Range(minScreen.x, maxScreen.x), Random.Range(minScreen.y, maxScreen.y), transform.position.z);
}
void OnMouseDown()
{
// You cannot drag it anymore if it is already placed!
if (isPlaced) return;
isDragging = true;
if (mySpawner != null) mySpawner.SetZoneHighlight(true);
zCoord = cam.WorldToScreenPoint(gameObject.transform.position).z;
dragOffset = gameObject.transform.position - GetMouseAsWorldPoint();
}
......@@ -72,7 +61,10 @@ public class FloatingDraggableRock : MonoBehaviour
{
isDragging = false;
// CHECK: Did we drop it on the ground?
// --- NEW: Tell Spawner to Turn OFF Highlight ---
if (mySpawner != null) mySpawner.SetZoneHighlight(false);
// -----------------------------------------------
if (isHoveringGround)
{
StickToGround();
......@@ -86,12 +78,7 @@ public class FloatingDraggableRock : MonoBehaviour
void StickToGround()
{
isPlaced = true;
// Tell the Spawner we did it
if (mySpawner != null)
{
mySpawner.RockPlaced();
}
if (mySpawner != null) mySpawner.RockPlaced();
}
private Vector3 GetMouseAsWorldPoint()
......@@ -101,21 +88,13 @@ public class FloatingDraggableRock : MonoBehaviour
return cam.ScreenToWorldPoint(mousePoint);
}
// --- COLLISION DETECTION ---
void OnTriggerEnter2D(Collider2D other)
{
// Make sure your Ground object has the Tag "Ground"
if (other.CompareTag("Ground"))
{
isHoveringGround = true;
}
if (other.CompareTag("Ground")) isHoveringGround = true;
}
void OnTriggerExit2D(Collider2D other)
{
if (other.CompareTag("Ground"))
{
isHoveringGround = false;
}
if (other.CompareTag("Ground")) isHoveringGround = false;
}
}
\ No newline at end of file
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.SceneManagement;
using UnityEngine.SceneManagement;
using AL_Arcade.DialogueSystem.Scripts;
public class ImageSwitcher : MonoBehaviour
{
......@@ -13,6 +14,7 @@ public class ImageSwitcher : MonoBehaviour
private int currentIndex = 0;
[SerializeField] string[] gameobjectives;
void Start()
{
if (pictures.Length > 0)
......@@ -45,9 +47,12 @@ public class ImageSwitcher : MonoBehaviour
if (currentIndex >= pictures.Length)
{
currentIndex = pictures.Length - 1;
}
pictures[currentIndex].SetActive(true);
GameContextBuilder.Instance.SetCurrentObjective(gameobjectives[currentIndex]);
if (currentIndex == pictures.Length - 1)
{
if (nextButton != null) nextButton.interactable = false;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment