From 7926bcdef4eea9e623a8f3aeafce0bc1aa008694 Mon Sep 17 00:00:00 2001 From: arlo Date: Mon, 18 Apr 2022 03:08:12 +0300 Subject: [PATCH 1/2] slime AI --- .../Animations/Arlo/Slime.controller | 157 ++++++++++------ Assets/Project Files/Scripts/Arlo/SlimeAI.cs | 49 ++++- Assets/Scenes/Arlo/Playground.unity | 168 +++++++++--------- 3 files changed, 238 insertions(+), 136 deletions(-) diff --git a/Assets/Project Files/Animations/Arlo/Slime.controller b/Assets/Project Files/Animations/Arlo/Slime.controller index b399a097..1ad6da76 100644 --- a/Assets/Project Files/Animations/Arlo/Slime.controller +++ b/Assets/Project Files/Animations/Arlo/Slime.controller @@ -20,7 +20,7 @@ AnimatorStateTransition: m_TransitionDuration: 0.25 m_TransitionOffset: 0 m_ExitTime: 0.85 - m_HasExitTime: 1 + m_HasExitTime: 0 m_HasFixedDuration: 1 m_InterruptionSource: 0 m_OrderedInterruption: 1 @@ -49,6 +49,7 @@ AnimatorState: m_CycleOffset: 0 m_Transitions: - {fileID: -5558417074028381841} + - {fileID: -1268510201227337377} m_StateMachineBehaviours: [] m_Position: {x: 50, y: 50, z: 0} m_IKOnFeet: 0 @@ -84,7 +85,32 @@ AnimatorStateTransition: m_TransitionDuration: 0.25 m_TransitionOffset: 0 m_ExitTime: 0.6875 - m_HasExitTime: 1 + m_HasExitTime: 0 + m_HasFixedDuration: 1 + m_InterruptionSource: 0 + m_OrderedInterruption: 1 + m_CanTransitionToSelf: 1 +--- !u!1101 &-5660328294272393165 +AnimatorStateTransition: + m_ObjectHideFlags: 1 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_Name: + m_Conditions: + - m_ConditionMode: 2 + m_ConditionEvent: EnemyInAttackRange + m_EventTreshold: 0 + m_DstStateMachine: {fileID: 0} + m_DstState: {fileID: -6878085496064969341} + m_Solo: 0 + m_Mute: 0 + m_IsExit: 0 + serializedVersion: 3 + m_TransitionDuration: 0.25 + m_TransitionOffset: 0 + m_ExitTime: 0.70000005 + m_HasExitTime: 0 m_HasFixedDuration: 1 m_InterruptionSource: 0 m_OrderedInterruption: 1 @@ -109,7 +135,7 @@ AnimatorStateTransition: m_TransitionDuration: 0.25 m_TransitionOffset: 0 m_ExitTime: 0.625 - m_HasExitTime: 1 + m_HasExitTime: 0 m_HasFixedDuration: 1 m_InterruptionSource: 0 m_OrderedInterruption: 1 @@ -124,7 +150,8 @@ AnimatorState: m_Name: EnemyAttack m_Speed: 1 m_CycleOffset: 0 - m_Transitions: [] + m_Transitions: + - {fileID: -5660328294272393165} m_StateMachineBehaviours: [] m_Position: {x: 50, y: 50, z: 0} m_IKOnFeet: 0 @@ -140,6 +167,56 @@ AnimatorState: m_MirrorParameter: m_CycleOffsetParameter: m_TimeParameter: +--- !u!1101 &-1918993004881361147 +AnimatorStateTransition: + m_ObjectHideFlags: 1 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_Name: + m_Conditions: + - m_ConditionMode: 2 + m_ConditionEvent: EnemyInVisionRange + m_EventTreshold: 0 + m_DstStateMachine: {fileID: 0} + m_DstState: {fileID: 1102546605246812244} + m_Solo: 0 + m_Mute: 0 + m_IsExit: 0 + serializedVersion: 3 + m_TransitionDuration: 0.25 + m_TransitionOffset: 0 + m_ExitTime: 0.6875 + m_HasExitTime: 0 + m_HasFixedDuration: 1 + m_InterruptionSource: 0 + m_OrderedInterruption: 1 + m_CanTransitionToSelf: 1 +--- !u!1101 &-1268510201227337377 +AnimatorStateTransition: + m_ObjectHideFlags: 1 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_Name: + m_Conditions: + - m_ConditionMode: 2 + m_ConditionEvent: EnemyInAggroRange + m_EventTreshold: 0 + m_DstStateMachine: {fileID: 0} + m_DstState: {fileID: 8194647877007136643} + m_Solo: 0 + m_Mute: 0 + m_IsExit: 0 + serializedVersion: 3 + m_TransitionDuration: 0.25 + m_TransitionOffset: 0 + m_ExitTime: 0.625 + m_HasExitTime: 0 + m_HasFixedDuration: 1 + m_InterruptionSource: 0 + m_OrderedInterruption: 1 + m_CanTransitionToSelf: 1 --- !u!91 &9100000 AnimatorController: m_ObjectHideFlags: 0 @@ -400,28 +477,6 @@ AnimatorStateTransition: m_InterruptionSource: 0 m_OrderedInterruption: 1 m_CanTransitionToSelf: 1 ---- !u!1101 &1101549165158824158 -AnimatorStateTransition: - m_ObjectHideFlags: 1 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_Name: - m_Conditions: [] - m_DstStateMachine: {fileID: 0} - m_DstState: {fileID: 1102835054974116572} - m_Solo: 0 - m_Mute: 0 - m_IsExit: 0 - serializedVersion: 3 - m_TransitionDuration: 0.25 - m_TransitionOffset: 0 - m_ExitTime: 4 - m_HasExitTime: 1 - m_HasFixedDuration: 1 - m_InterruptionSource: 0 - m_OrderedInterruption: 1 - m_CanTransitionToSelf: 1 --- !u!1101 &1101571659118250030 AnimatorStateTransition: m_ObjectHideFlags: 1 @@ -520,8 +575,7 @@ AnimatorState: m_Name: Dizzy m_Speed: 1 m_CycleOffset: 0 - m_Transitions: - - {fileID: 1101549165158824158} + m_Transitions: [] m_StateMachineBehaviours: [] m_Position: {x: 50, y: 50, z: 0} m_IKOnFeet: 0 @@ -979,74 +1033,74 @@ AnimatorStateMachine: m_ChildStates: - serializedVersion: 1 m_State: {fileID: 1102546605246812244} - m_Position: {x: 340, y: 30, z: 0} + m_Position: {x: 300, y: 140, z: 0} - serializedVersion: 1 m_State: {fileID: 1102428608990248820} - m_Position: {x: 1400, y: 60, z: 0} + m_Position: {x: 650, y: 120, z: 0} - serializedVersion: 1 m_State: {fileID: 1102941443349979230} - m_Position: {x: 1400, y: 140, z: 0} + m_Position: {x: 650, y: 200, z: 0} - serializedVersion: 1 m_State: {fileID: 1102311292720249994} - m_Position: {x: 1400, y: 220, z: 0} + m_Position: {x: 650, y: 280, z: 0} - serializedVersion: 1 m_State: {fileID: 1102508070621265122} - m_Position: {x: 1650, y: -30, z: 0} + m_Position: {x: 900, y: 30, z: 0} - serializedVersion: 1 m_State: {fileID: 1102615628393760256} - m_Position: {x: 1650, y: 60, z: 0} + m_Position: {x: 900, y: 120, z: 0} - serializedVersion: 1 m_State: {fileID: 1102840220384220776} - m_Position: {x: 1650, y: 140, z: 0} + m_Position: {x: 900, y: 200, z: 0} - serializedVersion: 1 m_State: {fileID: 1102224988525881432} - m_Position: {x: 1650, y: 220, z: 0} + m_Position: {x: 900, y: 280, z: 0} - serializedVersion: 1 m_State: {fileID: 1102906356952716468} - m_Position: {x: 1650, y: 310, z: 0} + m_Position: {x: 900, y: 370, z: 0} - serializedVersion: 1 m_State: {fileID: 1102275823511186668} - m_Position: {x: 1910, y: -30, z: 0} + m_Position: {x: 1160, y: 30, z: 0} - serializedVersion: 1 m_State: {fileID: 1102272222388203014} - m_Position: {x: 1910, y: 60, z: 0} + m_Position: {x: 1160, y: 120, z: 0} - serializedVersion: 1 m_State: {fileID: 1102080339498404604} - m_Position: {x: 1910, y: 140, z: 0} + m_Position: {x: 1160, y: 200, z: 0} - serializedVersion: 1 m_State: {fileID: 1102049015754028010} - m_Position: {x: 1910, y: 220, z: 0} + m_Position: {x: 1160, y: 280, z: 0} - serializedVersion: 1 m_State: {fileID: 1102486251471425260} - m_Position: {x: 1910, y: 310, z: 0} + m_Position: {x: 1160, y: 370, z: 0} - serializedVersion: 1 m_State: {fileID: 1102960180878307256} - m_Position: {x: 1840, y: 390, z: 0} + m_Position: {x: 670, y: 480, z: 0} - serializedVersion: 1 m_State: {fileID: 1102022585587399682} - m_Position: {x: 1650, y: 480, z: 0} + m_Position: {x: 670, y: 550, z: 0} - serializedVersion: 1 m_State: {fileID: 1102835054974116572} - m_Position: {x: 1270, y: 370, z: 0} + m_Position: {x: 280, y: 510, z: 0} - serializedVersion: 1 m_State: {fileID: 8194647877007136643} - m_Position: {x: 730, y: 20, z: 0} + m_Position: {x: 300, y: 220, z: 0} - serializedVersion: 1 m_State: {fileID: -1989803667490188130} - m_Position: {x: 760, y: 340, z: 0} + m_Position: {x: 300, y: 380, z: 0} - serializedVersion: 1 m_State: {fileID: -6878085496064969341} - m_Position: {x: 910, y: 170, z: 0} + m_Position: {x: 300, y: 300, z: 0} m_ChildStateMachines: [] m_AnyStateTransitions: [] m_EntryTransitions: [] m_StateMachineTransitions: {} m_StateMachineBehaviours: [] m_AnyStatePosition: {x: 50, y: 20, z: 0} - m_EntryPosition: {x: 50, y: 120, z: 0} - m_ExitPosition: {x: 48, y: 228, z: 0} + m_EntryPosition: {x: 100, y: 150, z: 0} + m_ExitPosition: {x: 90, y: 510, z: 0} m_ParentStateMachinePosition: {x: 800, y: 20, z: 0} - m_DefaultState: {fileID: -1989803667490188130} + m_DefaultState: {fileID: 1102546605246812244} --- !u!1102 &8194647877007136643 AnimatorState: serializedVersion: 6 @@ -1059,6 +1113,7 @@ AnimatorState: m_CycleOffset: 0 m_Transitions: - {fileID: -5882858675207143937} + - {fileID: -1918993004881361147} m_StateMachineBehaviours: [] m_Position: {x: 50, y: 50, z: 0} m_IKOnFeet: 0 diff --git a/Assets/Project Files/Scripts/Arlo/SlimeAI.cs b/Assets/Project Files/Scripts/Arlo/SlimeAI.cs index 07b08d9c..85b3a602 100644 --- a/Assets/Project Files/Scripts/Arlo/SlimeAI.cs +++ b/Assets/Project Files/Scripts/Arlo/SlimeAI.cs @@ -1,21 +1,68 @@ using System.Collections; using System.Collections.Generic; using UnityEngine; +using UnityEngine.Events; public class SlimeAI : MonoBehaviour { Animator animator; float playerDistance; + GameObject player; + + //[SerializeField] + //private UnityEvent onAttack; + // Start is called before the first frame update void Start() { animator = GetComponent(); + player = GameObject.FindWithTag("Player"); } // Update is called once per frame void Update() { - + playerDistance = Vector3.Distance(player.transform.position, transform.position); + if (playerDistance < 1.5) //Attack + { + animator.SetBool("EnemyInAttackRange", true); + animator.SetBool("EnemyInAggroRange", true); + animator.SetBool("EnemyInVisionRange", true); + Rotate(); + } + else if (playerDistance < 5) //Chase + { + animator.SetBool("EnemyInAttackRange", false); + animator.SetBool("EnemyInAggroRange", true); + animator.SetBool("EnemyInVisionRange", true); + Rotate(); + Move(); + } + else if (playerDistance < 8) //Stare + { + animator.SetBool("EnemyInAttackRange", false); + animator.SetBool("EnemyInAggroRange", false); + animator.SetBool("EnemyInVisionRange", true); + Rotate(); + } + else //Idle + { + animator.SetBool("EnemyInAttackRange", false); + animator.SetBool("EnemyInAggroRange", false); + animator.SetBool("EnemyInVisionRange", false); + } + } + void Rotate() + { + // Rotate the forward vector towards the target direction by one step + Vector3 newDirection = Vector3.RotateTowards(transform.forward, player.transform.position - transform.position, 1.0f * Time.deltaTime, 0.0f); + + // Calculate a rotation a step closer to the target and applies rotation to this object + transform.rotation = Quaternion.LookRotation(newDirection); + } + void Move() + { + transform.position += transform.forward * Time.deltaTime * 1.0f; } } diff --git a/Assets/Scenes/Arlo/Playground.unity b/Assets/Scenes/Arlo/Playground.unity index 36d628c8..2c6db37b 100644 --- a/Assets/Scenes/Arlo/Playground.unity +++ b/Assets/Scenes/Arlo/Playground.unity @@ -38,7 +38,7 @@ RenderSettings: m_ReflectionIntensity: 1 m_CustomReflection: {fileID: 0} m_Sun: {fileID: 705507994} - m_IndirectSpecularColor: {r: 0.09674972, g: 0.35171852, b: 0.7160277, a: 1} + m_IndirectSpecularColor: {r: 0.097786635, g: 0.3520055, b: 0.71981287, a: 1} m_UseRadianceAmbientProbe: 0 --- !u!157 &3 LightmapSettings: @@ -519,75 +519,6 @@ CanvasRenderer: m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 196031885} m_CullTransparentMesh: 1 ---- !u!1001 &421701411 -PrefabInstance: - m_ObjectHideFlags: 0 - serializedVersion: 2 - m_Modification: - m_TransformParent: {fileID: 0} - m_Modifications: - - target: {fileID: 8437010424349675124, guid: 288eb0a3190dc75419059ff7b4b70aa0, - type: 3} - propertyPath: m_Name - value: SlimePBR - objectReference: {fileID: 0} - - target: {fileID: 8439413668953451466, guid: 288eb0a3190dc75419059ff7b4b70aa0, - type: 3} - propertyPath: m_RootOrder - value: 1 - objectReference: {fileID: 0} - - target: {fileID: 8439413668953451466, guid: 288eb0a3190dc75419059ff7b4b70aa0, - type: 3} - propertyPath: m_LocalPosition.x - value: 3.546007 - objectReference: {fileID: 0} - - target: {fileID: 8439413668953451466, guid: 288eb0a3190dc75419059ff7b4b70aa0, - type: 3} - propertyPath: m_LocalPosition.y - value: 0.00000047683716 - objectReference: {fileID: 0} - - target: {fileID: 8439413668953451466, guid: 288eb0a3190dc75419059ff7b4b70aa0, - type: 3} - propertyPath: m_LocalPosition.z - value: -0.44001675 - objectReference: {fileID: 0} - - target: {fileID: 8439413668953451466, guid: 288eb0a3190dc75419059ff7b4b70aa0, - type: 3} - propertyPath: m_LocalRotation.w - value: 1 - objectReference: {fileID: 0} - - target: {fileID: 8439413668953451466, guid: 288eb0a3190dc75419059ff7b4b70aa0, - type: 3} - propertyPath: m_LocalRotation.x - value: 0 - objectReference: {fileID: 0} - - target: {fileID: 8439413668953451466, guid: 288eb0a3190dc75419059ff7b4b70aa0, - type: 3} - propertyPath: m_LocalRotation.y - value: 0 - objectReference: {fileID: 0} - - target: {fileID: 8439413668953451466, guid: 288eb0a3190dc75419059ff7b4b70aa0, - type: 3} - propertyPath: m_LocalRotation.z - value: 0 - objectReference: {fileID: 0} - - target: {fileID: 8439413668953451466, guid: 288eb0a3190dc75419059ff7b4b70aa0, - type: 3} - propertyPath: m_LocalEulerAnglesHint.x - value: 0 - objectReference: {fileID: 0} - - target: {fileID: 8439413668953451466, guid: 288eb0a3190dc75419059ff7b4b70aa0, - type: 3} - propertyPath: m_LocalEulerAnglesHint.y - value: 0 - objectReference: {fileID: 0} - - target: {fileID: 8439413668953451466, guid: 288eb0a3190dc75419059ff7b4b70aa0, - type: 3} - propertyPath: m_LocalEulerAnglesHint.z - value: 0 - objectReference: {fileID: 0} - m_RemovedComponents: [] - m_SourcePrefab: {fileID: 100100000, guid: 288eb0a3190dc75419059ff7b4b70aa0, type: 3} --- !u!1 &492689958 GameObject: m_ObjectHideFlags: 0 @@ -1160,7 +1091,7 @@ PrefabInstance: - target: {fileID: 6028983200900377696, guid: c89fd30ca0b56fb41a415d285d87b219, type: 3} propertyPath: m_RootOrder - value: 6 + value: 12 objectReference: {fileID: 0} - target: {fileID: 6028983200900377696, guid: c89fd30ca0b56fb41a415d285d87b219, type: 3} @@ -1229,7 +1160,7 @@ PrefabInstance: - target: {fileID: 553484814939433779, guid: dbc6a20437aec3141aaf8a552c1bc24f, type: 3} propertyPath: m_RootOrder - value: 3 + value: 6 objectReference: {fileID: 0} - target: {fileID: 553484814939433779, guid: dbc6a20437aec3141aaf8a552c1bc24f, type: 3} @@ -1479,7 +1410,7 @@ Transform: m_ConstrainProportionsScale: 0 m_Children: [] m_Father: {fileID: 0} - m_RootOrder: 0 + m_RootOrder: 2 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!114 &599916906 MonoBehaviour: @@ -1807,7 +1738,7 @@ Transform: m_ConstrainProportionsScale: 0 m_Children: [] m_Father: {fileID: 0} - m_RootOrder: 12 + m_RootOrder: 7 m_LocalEulerAnglesHint: {x: 50, y: -30, z: 0} --- !u!114 &705507996 MonoBehaviour: @@ -2050,7 +1981,7 @@ PrefabInstance: - target: {fileID: 988253026175434765, guid: 1931b899d98ae8543a827f11728cabe4, type: 3} propertyPath: m_RootOrder - value: 2 + value: 4 objectReference: {fileID: 0} - target: {fileID: 988253026175434765, guid: 1931b899d98ae8543a827f11728cabe4, type: 3} @@ -2283,7 +2214,7 @@ Transform: - {fileID: 1738326077} - {fileID: 1713108173} m_Father: {fileID: 0} - m_RootOrder: 11 + m_RootOrder: 5 m_LocalEulerAnglesHint: {x: 0, y: 115.775, z: 0} --- !u!1 &1520828248 GameObject: @@ -2435,7 +2366,7 @@ GameObject: - component: {fileID: 1578543177} m_Layer: 0 m_Name: XR Origin - m_TagString: Untagged + m_TagString: Player m_Icon: {fileID: 0} m_NavMeshLayer: 0 m_StaticEditorFlags: 0 @@ -2471,7 +2402,7 @@ Transform: m_Children: - {fileID: 508810528} m_Father: {fileID: 0} - m_RootOrder: 9 + m_RootOrder: 0 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!114 &1578543177 MonoBehaviour: @@ -2485,6 +2416,75 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: f121a54614abe5f4990620bfd6a1c96c, type: 3} m_Name: m_EditorClassIdentifier: +--- !u!1001 &1585303305 +PrefabInstance: + m_ObjectHideFlags: 0 + serializedVersion: 2 + m_Modification: + m_TransformParent: {fileID: 0} + m_Modifications: + - target: {fileID: 8437010424349675124, guid: 28785ec045ec00946ab767b14c8f4c6d, + type: 3} + propertyPath: m_Name + value: SlimePBR + objectReference: {fileID: 0} + - target: {fileID: 8439413668953451466, guid: 28785ec045ec00946ab767b14c8f4c6d, + type: 3} + propertyPath: m_RootOrder + value: 1 + objectReference: {fileID: 0} + - target: {fileID: 8439413668953451466, guid: 28785ec045ec00946ab767b14c8f4c6d, + type: 3} + propertyPath: m_LocalPosition.x + value: 5.33 + objectReference: {fileID: 0} + - target: {fileID: 8439413668953451466, guid: 28785ec045ec00946ab767b14c8f4c6d, + type: 3} + propertyPath: m_LocalPosition.y + value: 0.00000023841858 + objectReference: {fileID: 0} + - target: {fileID: 8439413668953451466, guid: 28785ec045ec00946ab767b14c8f4c6d, + type: 3} + propertyPath: m_LocalPosition.z + value: 11.57 + objectReference: {fileID: 0} + - target: {fileID: 8439413668953451466, guid: 28785ec045ec00946ab767b14c8f4c6d, + type: 3} + propertyPath: m_LocalRotation.w + value: 1 + objectReference: {fileID: 0} + - target: {fileID: 8439413668953451466, guid: 28785ec045ec00946ab767b14c8f4c6d, + type: 3} + propertyPath: m_LocalRotation.x + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 8439413668953451466, guid: 28785ec045ec00946ab767b14c8f4c6d, + type: 3} + propertyPath: m_LocalRotation.y + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 8439413668953451466, guid: 28785ec045ec00946ab767b14c8f4c6d, + type: 3} + propertyPath: m_LocalRotation.z + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 8439413668953451466, guid: 28785ec045ec00946ab767b14c8f4c6d, + type: 3} + propertyPath: m_LocalEulerAnglesHint.x + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 8439413668953451466, guid: 28785ec045ec00946ab767b14c8f4c6d, + type: 3} + propertyPath: m_LocalEulerAnglesHint.y + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 8439413668953451466, guid: 28785ec045ec00946ab767b14c8f4c6d, + type: 3} + propertyPath: m_LocalEulerAnglesHint.z + value: 0 + objectReference: {fileID: 0} + m_RemovedComponents: [] + m_SourcePrefab: {fileID: 100100000, guid: 28785ec045ec00946ab767b14c8f4c6d, type: 3} --- !u!4 &1636948867 stripped Transform: m_CorrespondingSourceObject: {fileID: 6178336183725213671, guid: d424f1b7b8f6a784c95e4f2d5872728e, @@ -2595,7 +2595,7 @@ Transform: m_ConstrainProportionsScale: 0 m_Children: [] m_Father: {fileID: 0} - m_RootOrder: 10 + m_RootOrder: 3 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!114 &1651537456 MonoBehaviour: @@ -3379,7 +3379,7 @@ Transform: m_ConstrainProportionsScale: 0 m_Children: [] m_Father: {fileID: 0} - m_RootOrder: 13 + m_RootOrder: 9 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1001 &1841330314 PrefabInstance: @@ -3391,7 +3391,7 @@ PrefabInstance: - target: {fileID: 6028983200900377696, guid: c89fd30ca0b56fb41a415d285d87b219, type: 3} propertyPath: m_RootOrder - value: 4 + value: 8 objectReference: {fileID: 0} - target: {fileID: 6028983200900377696, guid: c89fd30ca0b56fb41a415d285d87b219, type: 3} @@ -3705,7 +3705,7 @@ Transform: m_ConstrainProportionsScale: 0 m_Children: [] m_Father: {fileID: 0} - m_RootOrder: 8 + m_RootOrder: 13 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1001 &1993143051 PrefabInstance: @@ -3717,7 +3717,7 @@ PrefabInstance: - target: {fileID: 6028983200900377696, guid: c89fd30ca0b56fb41a415d285d87b219, type: 3} propertyPath: m_RootOrder - value: 5 + value: 10 objectReference: {fileID: 0} - target: {fileID: 6028983200900377696, guid: c89fd30ca0b56fb41a415d285d87b219, type: 3} @@ -3821,7 +3821,7 @@ PrefabInstance: - target: {fileID: 6028983200900377696, guid: c89fd30ca0b56fb41a415d285d87b219, type: 3} propertyPath: m_RootOrder - value: 7 + value: 11 objectReference: {fileID: 0} - target: {fileID: 6028983200900377696, guid: c89fd30ca0b56fb41a415d285d87b219, type: 3} From 4df9180db1de7f9e5cfa956f89672ed376e4e0ed Mon Sep 17 00:00:00 2001 From: arlo Date: Mon, 18 Apr 2022 18:06:39 +0300 Subject: [PATCH 2/2] 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: