diff --git a/.vscode/settings.json b/.vscode/settings.json index dab7915..f60b45a 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -60,12 +60,12 @@ "*.asset": "yaml", "*.meta": "yaml", "*.prefab": "yaml", - "*.unity": "yaml", + "*.unity": "yaml" }, "explorer.fileNesting.enabled": true, "explorer.fileNesting.patterns": { "*.sln": "*.csproj", "*.slnx": "*.csproj" }, - "dotnet.defaultSolution": "ZumbiGame.slnx" + "dotnet.defaultSolution": "zumbi-game.slnx" } \ No newline at end of file diff --git a/Assets/Prefabs/Zombie1.prefab b/Assets/Prefabs/Zombie1.prefab index 97945d5..6444bc4 100644 --- a/Assets/Prefabs/Zombie1.prefab +++ b/Assets/Prefabs/Zombie1.prefab @@ -1779,9 +1779,10 @@ GameObject: - component: {fileID: 7389507112651452681} - component: {fileID: 2441744333336506289} - component: {fileID: 5950679062911607196} + - component: {fileID: -7112169132516269854} m_Layer: 0 m_Name: Zombie1 - m_TagString: Untagged + m_TagString: Zombie m_Icon: {fileID: 0} m_NavMeshLayer: 0 m_StaticEditorFlags: 0 @@ -1886,6 +1887,19 @@ Rigidbody: m_Interpolate: 0 m_Constraints: 10 m_CollisionDetection: 0 +--- !u!114 &-7112169132516269854 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 4493914613880827488} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 9e6afdd2619c6db4e9c079733c664364, type: 3} + m_Name: + m_EditorClassIdentifier: Assembly-CSharp::ZombieController + maxHealth: 100 --- !u!1 &4710940672626480558 GameObject: m_ObjectHideFlags: 0 diff --git a/Assets/Scenes/MyFactory.unity b/Assets/Scenes/MyFactory.unity index 72e5a87..5de3f15 100644 --- a/Assets/Scenes/MyFactory.unity +++ b/Assets/Scenes/MyFactory.unity @@ -3374,7 +3374,10 @@ PrefabInstance: objectReference: {fileID: 0} m_RemovedComponents: [] m_RemovedGameObjects: [] - m_AddedGameObjects: [] + m_AddedGameObjects: + - targetCorrespondingSourceObject: {fileID: 4213711620244162979, guid: 87e308cb23eea97419b3c2623d8bb3fa, type: 3} + insertIndex: -1 + addedObject: {fileID: 796494257} m_AddedComponents: - targetCorrespondingSourceObject: {fileID: 4210100720165400533, guid: 87e308cb23eea97419b3c2623d8bb3fa, type: 3} insertIndex: -1 @@ -10071,6 +10074,37 @@ PrefabInstance: m_AddedGameObjects: [] m_AddedComponents: [] m_SourcePrefab: {fileID: 100100000, guid: 1a5f2b92e3d507a438173f443b67a160, type: 3} +--- !u!1 &796494256 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 796494257} + m_Layer: 0 + m_Name: MuzzlePoint + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!4 &796494257 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 796494256} + serializedVersion: 2 + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: 0.0031, y: 0.1004, z: 0.2019} + m_LocalScale: {x: 1, y: 1, z: 1} + m_ConstrainProportionsScale: 0 + m_Children: [] + m_Father: {fileID: 253752627} + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1001 &810837519 PrefabInstance: m_ObjectHideFlags: 0 @@ -26240,6 +26274,9 @@ MonoBehaviour: rightTriggerAction: {fileID: 83097790271614945, guid: c348712bda248c246b8c49b3db54643f, type: 3} audioSource: {fileID: 816325335} triggerSoundEffect: {fileID: 8300000, guid: 57e6ff823fc6f704f9d71aed80db932f, type: 3} + muzzlePoint: {fileID: 796494257} + maxRange: 100 + damage: 25 --- !u!1001 &1837025048 PrefabInstance: m_ObjectHideFlags: 0 diff --git a/Assets/Scripts/GunController.cs b/Assets/Scripts/GunController.cs index f94eb08..df465a7 100644 --- a/Assets/Scripts/GunController.cs +++ b/Assets/Scripts/GunController.cs @@ -9,6 +9,11 @@ public class GunController : MonoBehaviour [SerializeField] private AudioSource audioSource; [SerializeField] private AudioClip triggerSoundEffect; + [Header("Raycast")] + [SerializeField] private Transform muzzlePoint; + [SerializeField] private float maxRange = 100f; + [SerializeField] private float damage = 25f; + private void OnEnable() { rightTriggerAction.action.Enable(); @@ -28,7 +33,22 @@ public class GunController : MonoBehaviour private void HandleShoot() { - Debug.Log("Shoot!"); audioSource.PlayOneShot(triggerSoundEffect); + + Vector3 origin = muzzlePoint != null ? muzzlePoint.position : transform.position; + Vector3 direction = muzzlePoint != null ? muzzlePoint.forward : transform.forward; + + if (Physics.Raycast(origin, direction, out RaycastHit hit, maxRange)) + { + if (hit.collider.CompareTag("Zombie")) + { + if (hit.collider.TryGetComponent(out ZombieController zombie)) + { + zombie.TakeDamage(damage); + } + } + } + + Debug.DrawRay(origin, direction * maxRange, Color.red, 0.5f); } -} +} \ No newline at end of file diff --git a/Assets/Scripts/ZombieController.cs b/Assets/Scripts/ZombieController.cs new file mode 100644 index 0000000..3b62a97 --- /dev/null +++ b/Assets/Scripts/ZombieController.cs @@ -0,0 +1,29 @@ +using UnityEngine; + +public class ZombieController : MonoBehaviour +{ + [SerializeField] private float maxHealth = 100f; + private float currentHealth; + + private void Start() + { + currentHealth = maxHealth; + } + + public void TakeDamage(float amount) + { + currentHealth -= amount; + Debug.Log($"{gameObject.name} dostal {amount} damage. HP: {currentHealth}/{maxHealth}"); + + if (currentHealth <= 0) + { + Die(); + } + } + + private void Die() + { + Debug.Log($"{gameObject.name} je mŕtvy!"); + Destroy(gameObject); + } +} \ No newline at end of file diff --git a/Assets/Scripts/ZombieController.cs.meta b/Assets/Scripts/ZombieController.cs.meta new file mode 100644 index 0000000..d09ad91 --- /dev/null +++ b/Assets/Scripts/ZombieController.cs.meta @@ -0,0 +1,2 @@ +fileFormatVersion: 2 +guid: 9e6afdd2619c6db4e9c079733c664364 \ No newline at end of file diff --git a/ProjectSettings/TagManager.asset b/ProjectSettings/TagManager.asset index 3e9e3a1..035907d 100644 --- a/ProjectSettings/TagManager.asset +++ b/ProjectSettings/TagManager.asset @@ -5,6 +5,7 @@ TagManager: serializedVersion: 3 tags: - Anchor + - Zombie layers: - Default - TransparentFX diff --git a/zumbi-game.slnx b/zumbi-game.slnx new file mode 100644 index 0000000..3e88c01 --- /dev/null +++ b/zumbi-game.slnx @@ -0,0 +1,8 @@ + + + + + + + +