diff --git a/Assets/Prefabs/Enemies/Enemy.prefab b/Assets/Prefabs/Enemies/Enemy.prefab index 2b28d2c1..0708221b 100644 --- a/Assets/Prefabs/Enemies/Enemy.prefab +++ b/Assets/Prefabs/Enemies/Enemy.prefab @@ -9,6 +9,8 @@ GameObject: serializedVersion: 6 m_Component: - component: {fileID: 6058054806151542978} + - component: {fileID: 2957099991542780378} + - component: {fileID: 5199431160857003883} m_Layer: 0 m_Name: Enemy m_TagString: Untagged @@ -32,6 +34,47 @@ Transform: - {fileID: 1700549123680942451} m_Father: {fileID: 0} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!114 &2957099991542780378 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 4528139036750849664} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 5272ea2f30f4ddb488b557c786c790fa, type: 3} + m_Name: + m_EditorClassIdentifier: + health: 100 + isDead: 0 + onDied: + m_PersistentCalls: + m_Calls: + - m_Target: {fileID: 5199431160857003883} + m_TargetAssemblyTypeName: RagdollComponent, Assembly-CSharp + m_MethodName: Ragdoll + m_Mode: 1 + m_Arguments: + m_ObjectArgument: {fileID: 0} + m_ObjectArgumentAssemblyTypeName: UnityEngine.Object, UnityEngine + m_IntArgument: 0 + m_FloatArgument: 0 + m_StringArgument: + m_BoolArgument: 0 + m_CallState: 2 +--- !u!114 &5199431160857003883 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 4528139036750849664} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 90e2fe62ce2b65f4092a35e879751f60, type: 3} + m_Name: + m_EditorClassIdentifier: --- !u!1001 &1695861871456640983 PrefabInstance: m_ObjectHideFlags: 0 diff --git a/Assets/Scripts/Components/HealthComponent.cs b/Assets/Scripts/Components/HealthComponent.cs new file mode 100644 index 00000000..93d208f2 --- /dev/null +++ b/Assets/Scripts/Components/HealthComponent.cs @@ -0,0 +1,54 @@ +using Sirenix.OdinInspector; +using System.Collections; +using System.Collections.Generic; +using UnityEngine; +using UnityEngine.Events; +using UnityEngine.EventSystems; + +public class HealthComponent : MonoBehaviour +{ + [ReadOnly] + [SerializeField] + private int health; + + [ReadOnly] + [SerializeField] + private bool isDead; + + public UnityEvent onDied; + + [Button] + public void Setup() + { + health = 100; + isDead = false; + } + + public void TakeDamage(int damage) + { + health -= damage; + + if (health < 0) + { + health = 0; + } + + if (health == 0) + { + isDead = true; + onDied.Invoke(); + } + } + + [Button] + private void Take10Damage() + { + TakeDamage(10); + } + + [Button] + private void Kill() + { + TakeDamage(health); + } +} diff --git a/Assets/Scripts/Components/HealthComponent.cs.meta b/Assets/Scripts/Components/HealthComponent.cs.meta new file mode 100644 index 00000000..2a6173f2 --- /dev/null +++ b/Assets/Scripts/Components/HealthComponent.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 5272ea2f30f4ddb488b557c786c790fa +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Components/RagdollComponent.cs b/Assets/Scripts/Components/RagdollComponent.cs new file mode 100644 index 00000000..17f13a3f --- /dev/null +++ b/Assets/Scripts/Components/RagdollComponent.cs @@ -0,0 +1,25 @@ +using Sirenix.OdinInspector; +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class RagdollComponent : MonoBehaviour +{ + [Button] + public void Ragdoll() + { + var rigidBodies = GetComponentsInChildren(); + + foreach (var rb in rigidBodies) + { + rb.isKinematic = false; + } + + var animators = GetComponentsInChildren(); + + foreach (var a in animators) + { + a.enabled = false; + } + } +} diff --git a/Assets/Scripts/Components/RagdollComponent.cs.meta b/Assets/Scripts/Components/RagdollComponent.cs.meta new file mode 100644 index 00000000..9864fdf6 --- /dev/null +++ b/Assets/Scripts/Components/RagdollComponent.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 90e2fe62ce2b65f4092a35e879751f60 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Editor/OdinButtons.cs b/Assets/Scripts/Editor/OdinButtons.cs index 317ec918..dce586b9 100644 --- a/Assets/Scripts/Editor/OdinButtons.cs +++ b/Assets/Scripts/Editor/OdinButtons.cs @@ -14,13 +14,13 @@ public class OdinButtons : OdinEditorWindow GetWindow().Show(); } - [ButtonGroup] + [Button] private void ForgeScene() { LoadScene("Assets/Scenes/Forge.unity"); } - [ButtonGroup] + [Button] private void HurricaneExample() { LoadScene("Assets/HurricaneVR/TechDemo/Scenes/scene_examples.unity");