diff --git a/Assets/Prefabs/Enemy.prefab b/Assets/Prefabs/Enemy.prefab index c60080e..fa7fd2c 100644 --- a/Assets/Prefabs/Enemy.prefab +++ b/Assets/Prefabs/Enemy.prefab @@ -96,6 +96,12 @@ PrefabInstance: - targetCorrespondingSourceObject: {fileID: 5633379113638269974, guid: 6ea5f5e913c0b774fbcc2503ce1f5351, type: 3} insertIndex: -1 addedObject: {fileID: 180122570269065527} + - targetCorrespondingSourceObject: {fileID: 5633379113638269974, guid: 6ea5f5e913c0b774fbcc2503ce1f5351, type: 3} + insertIndex: -1 + addedObject: {fileID: 180122570269065528} + - targetCorrespondingSourceObject: {fileID: 5633379113638269974, guid: 6ea5f5e913c0b774fbcc2503ce1f5351, type: 3} + insertIndex: -1 + addedObject: {fileID: 180122570269065529} m_SourcePrefab: {fileID: 100100000, guid: 6ea5f5e913c0b774fbcc2503ce1f5351, type: 3} --- !u!1 &3184574949717094923 stripped GameObject: @@ -124,3 +130,31 @@ NavMeshAgent: m_BaseOffset: 0 m_WalkableMask: 4294967295 m_ObstacleAvoidanceType: 4 +--- !u!114 &180122570269065528 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 3184574949717094923} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: e2665e725aa6c7642bb84ea1a671970a, type: 3} + m_Name: + m_EditorClassIdentifier: Assembly-CSharp::EnemyHealth + maxHP: 100 +--- !u!114 &180122570269065529 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 3184574949717094923} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 29f907e38ca44e3495ce692733ada681, type: 3} + m_Name: + m_EditorClassIdentifier: Assembly-CSharp::EnemyShooter + shootRange: 25 + shootDelay: 1 + damage: 10 diff --git a/Assets/Scenes/Story1.unity b/Assets/Scenes/Story1.unity index f9655e0..ad49f59 100644 --- a/Assets/Scenes/Story1.unity +++ b/Assets/Scenes/Story1.unity @@ -1579,7 +1579,7 @@ RectTransform: m_GameObject: {fileID: 1597635426} m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} m_LocalPosition: {x: 0, y: 0, z: 0} - m_LocalScale: {x: 1, y: 1, z: 1} + m_LocalScale: {x: 0, y: 0, z: 0} m_ConstrainProportionsScale: 0 m_Children: - {fileID: 1783601023} @@ -2082,6 +2082,124 @@ Transform: m_CorrespondingSourceObject: {fileID: 7448449092846401218, guid: 46014def5fa85504abb9cc3190ae45e3, type: 3} m_PrefabInstance: {fileID: 79145418} m_PrefabAsset: {fileID: 0} +--- !u!1001 &3100000001 +PrefabInstance: + m_ObjectHideFlags: 0 + serializedVersion: 2 + m_Modification: + serializedVersion: 3 + m_TransformParent: {fileID: 0} + m_Modifications: + - target: {fileID: 666541161848099966, guid: c7fd2b64609ae0a4ba9c9021ccf720b7, type: 3} + propertyPath: m_LocalPosition.x + value: 515 + objectReference: {fileID: 0} + - target: {fileID: 666541161848099966, guid: c7fd2b64609ae0a4ba9c9021ccf720b7, type: 3} + propertyPath: m_LocalPosition.y + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 666541161848099966, guid: c7fd2b64609ae0a4ba9c9021ccf720b7, type: 3} + propertyPath: m_LocalPosition.z + value: 120 + objectReference: {fileID: 0} + - target: {fileID: 8869766472872964854, guid: c7fd2b64609ae0a4ba9c9021ccf720b7, type: 3} + propertyPath: m_Name + value: Test Geisel 1 + objectReference: {fileID: 0} + - target: {fileID: 8869766472872964854, guid: c7fd2b64609ae0a4ba9c9021ccf720b7, type: 3} + propertyPath: m_TagString + value: Untagged + objectReference: {fileID: 0} + m_RemovedComponents: + - {fileID: 180122570269065527, guid: c7fd2b64609ae0a4ba9c9021ccf720b7, type: 3} + - {fileID: 180122570269065528, guid: c7fd2b64609ae0a4ba9c9021ccf720b7, type: 3} + - {fileID: 180122570269065529, guid: c7fd2b64609ae0a4ba9c9021ccf720b7, type: 3} + m_RemovedGameObjects: [] + m_AddedGameObjects: [] + m_AddedComponents: + - targetCorrespondingSourceObject: {fileID: 3184574949717094923, guid: c7fd2b64609ae0a4ba9c9021ccf720b7, type: 3} + insertIndex: -1 + addedObject: {fileID: 3100000003} + m_SourcePrefab: {fileID: 100100000, guid: c7fd2b64609ae0a4ba9c9021ccf720b7, type: 3} +--- !u!1 &3100000002 stripped +GameObject: + m_CorrespondingSourceObject: {fileID: 3184574949717094923, guid: c7fd2b64609ae0a4ba9c9021ccf720b7, type: 3} + m_PrefabInstance: {fileID: 3100000001} + m_PrefabAsset: {fileID: 0} +--- !u!114 &3100000003 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 3100000002} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 62ea7866e4d846e2b5d207c6a3ec8afa, type: 3} + m_Name: + m_EditorClassIdentifier: Assembly-CSharp::HostageRescue + rescueDistance: 3 + escapeDistance: 15 + runSpeed: 5 +--- !u!1001 &3100000011 +PrefabInstance: + m_ObjectHideFlags: 0 + serializedVersion: 2 + m_Modification: + serializedVersion: 3 + m_TransformParent: {fileID: 0} + m_Modifications: + - target: {fileID: 666541161848099966, guid: c7fd2b64609ae0a4ba9c9021ccf720b7, type: 3} + propertyPath: m_LocalPosition.x + value: 500 + objectReference: {fileID: 0} + - target: {fileID: 666541161848099966, guid: c7fd2b64609ae0a4ba9c9021ccf720b7, type: 3} + propertyPath: m_LocalPosition.y + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 666541161848099966, guid: c7fd2b64609ae0a4ba9c9021ccf720b7, type: 3} + propertyPath: m_LocalPosition.z + value: 130 + objectReference: {fileID: 0} + - target: {fileID: 8869766472872964854, guid: c7fd2b64609ae0a4ba9c9021ccf720b7, type: 3} + propertyPath: m_Name + value: Test Geisel 2 + objectReference: {fileID: 0} + - target: {fileID: 8869766472872964854, guid: c7fd2b64609ae0a4ba9c9021ccf720b7, type: 3} + propertyPath: m_TagString + value: Untagged + objectReference: {fileID: 0} + m_RemovedComponents: + - {fileID: 180122570269065527, guid: c7fd2b64609ae0a4ba9c9021ccf720b7, type: 3} + - {fileID: 180122570269065528, guid: c7fd2b64609ae0a4ba9c9021ccf720b7, type: 3} + - {fileID: 180122570269065529, guid: c7fd2b64609ae0a4ba9c9021ccf720b7, type: 3} + m_RemovedGameObjects: [] + m_AddedGameObjects: [] + m_AddedComponents: + - targetCorrespondingSourceObject: {fileID: 3184574949717094923, guid: c7fd2b64609ae0a4ba9c9021ccf720b7, type: 3} + insertIndex: -1 + addedObject: {fileID: 3100000013} + m_SourcePrefab: {fileID: 100100000, guid: c7fd2b64609ae0a4ba9c9021ccf720b7, type: 3} +--- !u!1 &3100000012 stripped +GameObject: + m_CorrespondingSourceObject: {fileID: 3184574949717094923, guid: c7fd2b64609ae0a4ba9c9021ccf720b7, type: 3} + m_PrefabInstance: {fileID: 3100000011} + m_PrefabAsset: {fileID: 0} +--- !u!114 &3100000013 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 3100000012} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 62ea7866e4d846e2b5d207c6a3ec8afa, type: 3} + m_Name: + m_EditorClassIdentifier: Assembly-CSharp::HostageRescue + rescueDistance: 3 + escapeDistance: 15 + runSpeed: 5 --- !u!1660057539 &9223372036854775807 SceneRoots: m_ObjectHideFlags: 0 @@ -2095,3 +2213,5 @@ SceneRoots: - {fileID: 896204980} - {fileID: 535044337} - {fileID: 1597635430} + - {fileID: 3100000001} + - {fileID: 3100000011} diff --git a/Assets/Scripts/EnemyShooter.cs b/Assets/Scripts/EnemyShooter.cs new file mode 100644 index 0000000..50b1658 --- /dev/null +++ b/Assets/Scripts/EnemyShooter.cs @@ -0,0 +1,46 @@ +using UnityEngine; + +public class EnemyShooter : MonoBehaviour +{ + public float shootRange = 25f; + public float shootDelay = 1f; + public int damage = 10; + + private PlayerHealth player; + private float nextShotTime; + + void Start() + { + player = FindFirstObjectByType(); + } + + void Update() + { + if (PauseMenu.GameIsPaused || player == null) return; + + Vector3 direction = player.transform.position - transform.position; + if (direction.magnitude > shootRange) return; + + direction.y = 0f; + if (direction != Vector3.zero) + transform.rotation = Quaternion.LookRotation(direction); + + if (Time.time >= nextShotTime && CanSeePlayer()) + { + player.TakeDamage(damage); + nextShotTime = Time.time + shootDelay; + } + } + + bool CanSeePlayer() + { + Vector3 start = transform.position + Vector3.up; + Vector3 target = player.transform.position + Vector3.up; + Vector3 direction = target - start; + + if (Physics.Raycast(start, direction.normalized, out RaycastHit hit, shootRange)) + return hit.collider.GetComponentInParent() != null; + + return false; + } +} diff --git a/Assets/Scripts/EnemyShooter.cs.meta b/Assets/Scripts/EnemyShooter.cs.meta new file mode 100644 index 0000000..9b9b9c6 --- /dev/null +++ b/Assets/Scripts/EnemyShooter.cs.meta @@ -0,0 +1,2 @@ +fileFormatVersion: 2 +guid: 29f907e38ca44e3495ce692733ada681 diff --git a/Assets/Scripts/HostageRescue.cs b/Assets/Scripts/HostageRescue.cs new file mode 100644 index 0000000..7d7e3e1 --- /dev/null +++ b/Assets/Scripts/HostageRescue.cs @@ -0,0 +1,49 @@ +using UnityEngine; + +public class HostageRescue : MonoBehaviour +{ + public float rescueDistance = 3f; + public float escapeDistance = 15f; + public float runSpeed = 5f; + + private Transform player; + private bool rescued; + private Vector3 escapeDirection; + private Vector3 startPosition; + + void Start() + { + PlayerHealth playerHealth = FindFirstObjectByType(); + if (playerHealth != null) player = playerHealth.transform; + + startPosition = transform.position; + } + + void Update() + { + if (PauseMenu.GameIsPaused || player == null) return; + + if (rescued) + { + transform.position += escapeDirection * runSpeed * Time.deltaTime; + if (Vector3.Distance(startPosition, transform.position) >= escapeDistance) + enabled = false; + return; + } + + if (Vector3.Distance(transform.position, player.position) <= rescueDistance && + Input.GetKeyDown(KeyCode.E)) + { + RunAway(); + } + } + + void RunAway() + { + rescued = true; + startPosition = transform.position; + escapeDirection = (transform.position - player.position).normalized; + escapeDirection.y = 0f; + transform.rotation = Quaternion.LookRotation(escapeDirection); + } +} diff --git a/Assets/Scripts/HostageRescue.cs.meta b/Assets/Scripts/HostageRescue.cs.meta new file mode 100644 index 0000000..822696f --- /dev/null +++ b/Assets/Scripts/HostageRescue.cs.meta @@ -0,0 +1,2 @@ +fileFormatVersion: 2 +guid: 62ea7866e4d846e2b5d207c6a3ec8afa