TEST: trap and shakecam
This commit is contained in:
8
Assets/Scripts/Manager.meta
Normal file
8
Assets/Scripts/Manager.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a48b89f983fff0642987cca2cb779dd4
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
17
Assets/Scripts/Manager/DeathTrapCollision.cs
Normal file
17
Assets/Scripts/Manager/DeathTrapCollision.cs
Normal file
@@ -0,0 +1,17 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class DeathTrapCollision : MonoBehaviour {
|
||||
private void OnTriggerEnter(Collider other) {
|
||||
// Check if the object colliding with the trap is the player
|
||||
// Assumes the player character (e.g., Bob) has the tag "Player"
|
||||
if (other.CompareTag("Player")) {
|
||||
// Trigger the Game Over event via the GameManager
|
||||
FindObjectOfType<GameManager>().TriggerGameOver();
|
||||
|
||||
// Destroy the player object upon collision
|
||||
Destroy(other.gameObject);
|
||||
}
|
||||
}
|
||||
}
|
||||
2
Assets/Scripts/Manager/DeathTrapCollision.cs.meta
Normal file
2
Assets/Scripts/Manager/DeathTrapCollision.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1746534d206b0fe4b8e895df471d3d56
|
||||
62
Assets/Scripts/Manager/DeathTrapSpawner.cs
Normal file
62
Assets/Scripts/Manager/DeathTrapSpawner.cs
Normal file
@@ -0,0 +1,62 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class DeathTrapSpawner : MonoBehaviour {
|
||||
public GameObject deathTrapPrefab; // Prefab for the death trap
|
||||
public float spawnInterval = 10f; // Time interval between spawns
|
||||
public float minLifetime = 3f; // Minimum lifetime of the death trap
|
||||
public float maxLifetime = 8f; // Maximum lifetime of the death trap
|
||||
|
||||
private Vector3 GetRandomPosition() {
|
||||
Vector3 randomPosition;
|
||||
int attempts = 0;
|
||||
|
||||
do {
|
||||
// Generate random X and Z positions rounded to nearest 10, then offset by 5
|
||||
float x = Mathf.Round(Random.Range(-45f, 45f) / 10f) * 10f + 5f;
|
||||
float z = Mathf.Round(Random.Range(-45f, 45f) / 10f) * 10f + 5f;
|
||||
|
||||
// Fixed Y position for traps
|
||||
randomPosition = new Vector3(x, 3.5f, z);
|
||||
|
||||
attempts++;
|
||||
if (attempts > 100) {
|
||||
Debug.LogWarning("No valid position found for the death trap.");
|
||||
|
||||
// Exit if too many attempts are made
|
||||
break;
|
||||
}
|
||||
}
|
||||
while (
|
||||
Physics.CheckBox(randomPosition, new Vector3(2.5f, 3.5f, 2.5f), Quaternion.identity, LayerMask.GetMask("Walls")) || // Check for walls
|
||||
Physics.CheckBox(randomPosition, new Vector3(2.5f, 3.5f, 2.5f), Quaternion.identity, LayerMask.GetMask("Collectible")) || // Check for collectibles
|
||||
Physics.CheckBox(randomPosition, new Vector3(2.5f, 3.5f, 2.5f), Quaternion.identity, LayerMask.GetMask("Player")) // Check for player
|
||||
);
|
||||
|
||||
// Return a valid position for the death trap
|
||||
return randomPosition;
|
||||
}
|
||||
|
||||
private IEnumerator SpawnDeathTraps() {
|
||||
while (true) {
|
||||
// Generate a random spawn position
|
||||
Vector3 spawnPosition = GetRandomPosition();
|
||||
|
||||
// Spawn a new death trap at the random position
|
||||
GameObject deathTrap = Instantiate(deathTrapPrefab, spawnPosition, Quaternion.identity);
|
||||
|
||||
// Determine a random lifetime for the trap and destroy it after that time
|
||||
float lifetime = Random.Range(minLifetime, maxLifetime);
|
||||
Destroy(deathTrap, lifetime);
|
||||
|
||||
// Wait for the specified spawn interval before spawning the next trap
|
||||
yield return new WaitForSeconds(spawnInterval);
|
||||
}
|
||||
}
|
||||
|
||||
private void Start() {
|
||||
// Start the coroutine to spawn death traps
|
||||
StartCoroutine(SpawnDeathTraps());
|
||||
}
|
||||
}
|
||||
2
Assets/Scripts/Manager/DeathTrapSpawner.cs.meta
Normal file
2
Assets/Scripts/Manager/DeathTrapSpawner.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ca1a9a3813a058946990c84846f54c17
|
||||
35
Assets/Scripts/Manager/GameManager.cs
Normal file
35
Assets/Scripts/Manager/GameManager.cs
Normal file
@@ -0,0 +1,35 @@
|
||||
using Fusion;
|
||||
using TMPro;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class GameManager : NetworkBehaviour
|
||||
{
|
||||
public Text gameOverText; // Reference to the Game Over text UI element
|
||||
|
||||
private bool isGameOver = false; // Flag to check if the game is over
|
||||
|
||||
private void Start() {
|
||||
if (gameOverText != null) {
|
||||
// Ensure the Game Over text is hidden at the start of the game
|
||||
gameOverText.gameObject.SetActive(false);
|
||||
}
|
||||
}
|
||||
|
||||
public void TriggerGameOver() {
|
||||
if (!isGameOver) {
|
||||
// Mark the game as over
|
||||
isGameOver = true;
|
||||
|
||||
if (gameOverText != null) {
|
||||
// Display the Game Over text
|
||||
gameOverText.gameObject.SetActive(true);
|
||||
}
|
||||
|
||||
// Freeze the game by setting the time scale to 0
|
||||
Time.timeScale = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
2
Assets/Scripts/Manager/GameManager.cs.meta
Normal file
2
Assets/Scripts/Manager/GameManager.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1180f4b733c7599498f6eb4e77848e23
|
||||
Reference in New Issue
Block a user