Create Health and Ragdoll component and and them to enemy

This commit is contained in:
2024-08-09 17:36:09 +02:00
parent 01c6f898f3
commit f3623c6036
6 changed files with 146 additions and 2 deletions

View File

@@ -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);
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 5272ea2f30f4ddb488b557c786c790fa
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -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<Rigidbody>();
foreach (var rb in rigidBodies)
{
rb.isKinematic = false;
}
var animators = GetComponentsInChildren<Animator>();
foreach (var a in animators)
{
a.enabled = false;
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 90e2fe62ce2b65f4092a35e879751f60
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -14,13 +14,13 @@ public class OdinButtons : OdinEditorWindow
GetWindow<OdinButtons>().Show();
}
[ButtonGroup]
[Button]
private void ForgeScene()
{
LoadScene("Assets/Scenes/Forge.unity");
}
[ButtonGroup]
[Button]
private void HurricaneExample()
{
LoadScene("Assets/HurricaneVR/TechDemo/Scenes/scene_examples.unity");