Create Health and Ragdoll component and and them to enemy
This commit is contained in:
@@ -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
|
||||
|
||||
54
Assets/Scripts/Components/HealthComponent.cs
Normal file
54
Assets/Scripts/Components/HealthComponent.cs
Normal 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);
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/Components/HealthComponent.cs.meta
Normal file
11
Assets/Scripts/Components/HealthComponent.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5272ea2f30f4ddb488b557c786c790fa
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
25
Assets/Scripts/Components/RagdollComponent.cs
Normal file
25
Assets/Scripts/Components/RagdollComponent.cs
Normal 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/Components/RagdollComponent.cs.meta
Normal file
11
Assets/Scripts/Components/RagdollComponent.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 90e2fe62ce2b65f4092a35e879751f60
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -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");
|
||||
|
||||
Reference in New Issue
Block a user