Completed:TeleportTrap && Write:GameManager
This commit is contained in:
@@ -1,17 +0,0 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,2 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1746534d206b0fe4b8e895df471d3d56
|
||||
8
Assets/Scripts/Trap.meta
Normal file
8
Assets/Scripts/Trap.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 82bfa2ea8f45df942b2e9d2855a5ff6e
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,12 +1,8 @@
|
||||
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
|
||||
public class TeleportTrap : MonoBehaviour {
|
||||
|
||||
|
||||
private Vector3 GetRandomPosition() {
|
||||
Vector3 randomPosition;
|
||||
@@ -38,25 +34,16 @@ public class DeathTrapSpawner : MonoBehaviour {
|
||||
return randomPosition;
|
||||
}
|
||||
|
||||
private IEnumerator SpawnDeathTraps() {
|
||||
while (true) {
|
||||
// Generate a random spawn position
|
||||
Vector3 spawnPosition = GetRandomPosition();
|
||||
private Vector3 GetPositionTeleport() {
|
||||
Vector3 spawnPosition = GetRandomPosition();
|
||||
return spawnPosition;
|
||||
}
|
||||
|
||||
// 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 OnCollisionEnter(Collision collision)
|
||||
{
|
||||
if (collision.gameObject.CompareTag("Player"))
|
||||
{
|
||||
collision.transform.position = GetPositionTeleport();
|
||||
}
|
||||
}
|
||||
|
||||
private void Start() {
|
||||
// Start the coroutine to spawn death traps
|
||||
StartCoroutine(SpawnDeathTraps());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user