Completed:TeleportTrap && Write:GameManager
This commit is contained in:
@@ -419,10 +419,67 @@ MonoBehaviour:
|
|||||||
m_Script: {fileID: 11500000, guid: ca1a9a3813a058946990c84846f54c17, type: 3}
|
m_Script: {fileID: 11500000, guid: ca1a9a3813a058946990c84846f54c17, type: 3}
|
||||||
m_Name:
|
m_Name:
|
||||||
m_EditorClassIdentifier: Assembly-CSharp::DeathTrapSpawner
|
m_EditorClassIdentifier: Assembly-CSharp::DeathTrapSpawner
|
||||||
deathTrapPrefab: {fileID: 6121659928201372921, guid: 2489c1d80f2f9074888a06f59f372161, type: 3}
|
--- !u!1001 &1436576813
|
||||||
spawnInterval: 10
|
PrefabInstance:
|
||||||
minLifetime: 3
|
m_ObjectHideFlags: 0
|
||||||
maxLifetime: 8
|
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
|
--- !u!1 &1490570703
|
||||||
GameObject:
|
GameObject:
|
||||||
m_ObjectHideFlags: 0
|
m_ObjectHideFlags: 0
|
||||||
@@ -908,7 +965,8 @@ PrefabInstance:
|
|||||||
propertyPath: m_LocalEulerAnglesHint.z
|
propertyPath: m_LocalEulerAnglesHint.z
|
||||||
value: 0
|
value: 0
|
||||||
objectReference: {fileID: 0}
|
objectReference: {fileID: 0}
|
||||||
m_RemovedComponents: []
|
m_RemovedComponents:
|
||||||
|
- {fileID: 8714104882223651289, guid: 2489c1d80f2f9074888a06f59f372161, type: 3}
|
||||||
m_RemovedGameObjects: []
|
m_RemovedGameObjects: []
|
||||||
m_AddedGameObjects: []
|
m_AddedGameObjects: []
|
||||||
m_AddedComponents: []
|
m_AddedComponents: []
|
||||||
@@ -920,3 +978,4 @@ SceneRoots:
|
|||||||
- {fileID: 2120030154}
|
- {fileID: 2120030154}
|
||||||
- {fileID: 982050945}
|
- {fileID: 982050945}
|
||||||
- {fileID: 4899204113511701172}
|
- {fileID: 4899204113511701172}
|
||||||
|
- {fileID: 1436576813}
|
||||||
|
|||||||
@@ -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;
|
using UnityEngine;
|
||||||
|
|
||||||
public class DeathTrapSpawner : MonoBehaviour {
|
public class TeleportTrap : 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() {
|
private Vector3 GetRandomPosition() {
|
||||||
Vector3 randomPosition;
|
Vector3 randomPosition;
|
||||||
@@ -38,25 +34,16 @@ public class DeathTrapSpawner : MonoBehaviour {
|
|||||||
return randomPosition;
|
return randomPosition;
|
||||||
}
|
}
|
||||||
|
|
||||||
private IEnumerator SpawnDeathTraps() {
|
private Vector3 GetPositionTeleport() {
|
||||||
while (true) {
|
Vector3 spawnPosition = GetRandomPosition();
|
||||||
// Generate a random spawn position
|
return spawnPosition;
|
||||||
Vector3 spawnPosition = GetRandomPosition();
|
}
|
||||||
|
|
||||||
// Spawn a new death trap at the random position
|
private void OnCollisionEnter(Collision collision)
|
||||||
GameObject deathTrap = Instantiate(deathTrapPrefab, spawnPosition, Quaternion.identity);
|
{
|
||||||
|
if (collision.gameObject.CompareTag("Player"))
|
||||||
// Determine a random lifetime for the trap and destroy it after that time
|
{
|
||||||
float lifetime = Random.Range(minLifetime, maxLifetime);
|
collision.transform.position = GetPositionTeleport();
|
||||||
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());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user