Completed:TeleportTrap && Write:GameManager

This commit is contained in:
manhduyhoang90
2026-05-22 19:27:06 +07:00
parent 517de4acb0
commit 82b7d47285
6 changed files with 84 additions and 49 deletions

View File

@@ -419,10 +419,67 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: ca1a9a3813a058946990c84846f54c17, type: 3}
m_Name:
m_EditorClassIdentifier: Assembly-CSharp::DeathTrapSpawner
deathTrapPrefab: {fileID: 6121659928201372921, guid: 2489c1d80f2f9074888a06f59f372161, type: 3}
spawnInterval: 10
minLifetime: 3
maxLifetime: 8
--- !u!1001 &1436576813
PrefabInstance:
m_ObjectHideFlags: 0
serializedVersion: 2
m_Modification:
serializedVersion: 3
m_TransformParent: {fileID: 0}
m_Modifications:
- target: {fileID: -5076913349690967641, guid: 761bdf2e5c0cff4488527355acb975e5, type: 3}
propertyPath: SortKey
value: 3478665629
objectReference: {fileID: 0}
- target: {fileID: 1054594849095937263, guid: 761bdf2e5c0cff4488527355acb975e5, type: 3}
propertyPath: m_Name
value: Player
objectReference: {fileID: 0}
- target: {fileID: 3154409663696148700, guid: 761bdf2e5c0cff4488527355acb975e5, type: 3}
propertyPath: m_LocalPosition.x
value: 2.43947
objectReference: {fileID: 0}
- target: {fileID: 3154409663696148700, guid: 761bdf2e5c0cff4488527355acb975e5, type: 3}
propertyPath: m_LocalPosition.y
value: -4.20374
objectReference: {fileID: 0}
- target: {fileID: 3154409663696148700, guid: 761bdf2e5c0cff4488527355acb975e5, type: 3}
propertyPath: m_LocalPosition.z
value: -9.47261
objectReference: {fileID: 0}
- target: {fileID: 3154409663696148700, guid: 761bdf2e5c0cff4488527355acb975e5, type: 3}
propertyPath: m_LocalRotation.w
value: 1
objectReference: {fileID: 0}
- target: {fileID: 3154409663696148700, guid: 761bdf2e5c0cff4488527355acb975e5, type: 3}
propertyPath: m_LocalRotation.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 3154409663696148700, guid: 761bdf2e5c0cff4488527355acb975e5, type: 3}
propertyPath: m_LocalRotation.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 3154409663696148700, guid: 761bdf2e5c0cff4488527355acb975e5, type: 3}
propertyPath: m_LocalRotation.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 3154409663696148700, guid: 761bdf2e5c0cff4488527355acb975e5, type: 3}
propertyPath: m_LocalEulerAnglesHint.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 3154409663696148700, guid: 761bdf2e5c0cff4488527355acb975e5, type: 3}
propertyPath: m_LocalEulerAnglesHint.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 3154409663696148700, guid: 761bdf2e5c0cff4488527355acb975e5, type: 3}
propertyPath: m_LocalEulerAnglesHint.z
value: 0
objectReference: {fileID: 0}
m_RemovedComponents: []
m_RemovedGameObjects: []
m_AddedGameObjects: []
m_AddedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: 761bdf2e5c0cff4488527355acb975e5, type: 3}
--- !u!1 &1490570703
GameObject:
m_ObjectHideFlags: 0
@@ -908,7 +965,8 @@ PrefabInstance:
propertyPath: m_LocalEulerAnglesHint.z
value: 0
objectReference: {fileID: 0}
m_RemovedComponents: []
m_RemovedComponents:
- {fileID: 8714104882223651289, guid: 2489c1d80f2f9074888a06f59f372161, type: 3}
m_RemovedGameObjects: []
m_AddedGameObjects: []
m_AddedComponents: []
@@ -920,3 +978,4 @@ SceneRoots:
- {fileID: 2120030154}
- {fileID: 982050945}
- {fileID: 4899204113511701172}
- {fileID: 1436576813}

View File

@@ -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);
}
}
}

View File

@@ -1,2 +0,0 @@
fileFormatVersion: 2
guid: 1746534d206b0fe4b8e895df471d3d56

8
Assets/Scripts/Trap.meta Normal file
View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 82bfa2ea8f45df942b2e9d2855a5ff6e
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -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());
}
}