add zombie controller and implement damage system; update gun controller for raycasting; modify prefab and scene settings

This commit is contained in:
dkecskes
2026-05-04 12:39:20 +02:00
parent 957f8845b9
commit 835127238a
8 changed files with 117 additions and 6 deletions
+2 -2
View File
@@ -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"
}
+15 -1
View File
@@ -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
+38 -1
View File
@@ -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
+21 -1
View File
@@ -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);
}
}
+29
View File
@@ -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);
}
}
+2
View File
@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 9e6afdd2619c6db4e9c079733c664364
+1
View File
@@ -5,6 +5,7 @@ TagManager:
serializedVersion: 3
tags:
- Anchor
- Zombie
layers:
- Default
- TransparentFX
+8
View File
@@ -0,0 +1,8 @@
<Solution>
<Project Path="Unity.XR.Interaction.Toolkit.Samples.StarterAssets.csproj" />
<Project Path="Assembly-CSharp.csproj" />
<Project Path="Unity.XR.Interaction.Toolkit.Samples.Hands.Editor.csproj" />
<Project Path="Unity.XR.Interaction.Toolkit.Samples.Hands.csproj" />
<Project Path="Unity.XR.Hands.Samples.VisualizerSample.csproj" />
<Project Path="Unity.XR.Interaction.Toolkit.Samples.StarterAssets.Editor.csproj" />
</Solution>