From 4df9180db1de7f9e5cfa956f89672ed376e4e0ed Mon Sep 17 00:00:00 2001 From: arlo Date: Mon, 18 Apr 2022 18:06:39 +0300 Subject: [PATCH] slimes now die and disappear after death --- .../Animations/Arlo/Slime.controller | 2 +- Assets/Project Files/Scripts/Arlo/SlimeAI.cs | 16 +++++++++ .../Project Files/Scripts/Arlo/SlimeDeath.cs | 36 +++++++++++++++++++ .../Scripts/Arlo/SlimeDeath.cs.meta | 11 ++++++ 4 files changed, 64 insertions(+), 1 deletion(-) create mode 100644 Assets/Project Files/Scripts/Arlo/SlimeDeath.cs create mode 100644 Assets/Project Files/Scripts/Arlo/SlimeDeath.cs.meta diff --git a/Assets/Project Files/Animations/Arlo/Slime.controller b/Assets/Project Files/Animations/Arlo/Slime.controller index 1ad6da76..7238d8c6 100644 --- a/Assets/Project Files/Animations/Arlo/Slime.controller +++ b/Assets/Project Files/Animations/Arlo/Slime.controller @@ -59,7 +59,7 @@ AnimatorState: m_MirrorParameterActive: 0 m_CycleOffsetParameterActive: 0 m_TimeParameterActive: 0 - m_Motion: {fileID: 7400000, guid: dbf4e442d523220489ca9531ab20161f, type: 3} + m_Motion: {fileID: 7400000, guid: f5d4d1a7dadc5a84d910c492d947ca4f, type: 3} m_Tag: m_SpeedParameter: m_MirrorParameter: diff --git a/Assets/Project Files/Scripts/Arlo/SlimeAI.cs b/Assets/Project Files/Scripts/Arlo/SlimeAI.cs index 85b3a602..fcc27d0b 100644 --- a/Assets/Project Files/Scripts/Arlo/SlimeAI.cs +++ b/Assets/Project Files/Scripts/Arlo/SlimeAI.cs @@ -9,6 +9,7 @@ public class SlimeAI : MonoBehaviour Animator animator; float playerDistance; GameObject player; + int HP; //[SerializeField] //private UnityEvent onAttack; @@ -18,6 +19,7 @@ public class SlimeAI : MonoBehaviour { animator = GetComponent(); player = GameObject.FindWithTag("Player"); + HP = 10; } // Update is called once per frame @@ -52,6 +54,15 @@ public class SlimeAI : MonoBehaviour animator.SetBool("EnemyInAggroRange", false); animator.SetBool("EnemyInVisionRange", false); } + if (HP <= 0) + { + animator.SetBool("Dead", true); + } + if (animator.GetBool("DeathComplete")) + { + print("asd"); + Destroy(this.gameObject); + } } void Rotate() { @@ -65,4 +76,9 @@ public class SlimeAI : MonoBehaviour { transform.position += transform.forward * Time.deltaTime * 1.0f; } + + public void GetHit(int dmg) + { + HP -= dmg; + } } diff --git a/Assets/Project Files/Scripts/Arlo/SlimeDeath.cs b/Assets/Project Files/Scripts/Arlo/SlimeDeath.cs new file mode 100644 index 00000000..de9de0c7 --- /dev/null +++ b/Assets/Project Files/Scripts/Arlo/SlimeDeath.cs @@ -0,0 +1,36 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class death : StateMachineBehaviour +{ + // OnStateEnter is called when a transition starts and the state machine starts to evaluate this state + //override public void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) + //{ + // + //} + + // OnStateUpdate is called on each Update frame between OnStateEnter and OnStateExit callbacks + //override public void OnStateUpdate(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) + //{ + // + //} + + // OnStateExit is called when a transition ends and the state machine finishes evaluating this state + //override public void OnStateExit(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) + //{ + // + //} + + // OnStateMove is called right after Animator.OnAnimatorMove() + //override public void OnStateMove(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) + //{ + // // Implement code that processes and affects root motion + //} + + // OnStateIK is called right after Animator.OnAnimatorIK() + //override public void OnStateIK(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) + //{ + // // Implement code that sets up animation IK (inverse kinematics) + //} +} diff --git a/Assets/Project Files/Scripts/Arlo/SlimeDeath.cs.meta b/Assets/Project Files/Scripts/Arlo/SlimeDeath.cs.meta new file mode 100644 index 00000000..f50f4eb4 --- /dev/null +++ b/Assets/Project Files/Scripts/Arlo/SlimeDeath.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 6c7f89faf36f41b418e5105a12c34cdb +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: