fixes to slime death, attack function has proper timings
This commit is contained in:
parent
a748b342a8
commit
5a83699fd1
|
@ -217,6 +217,28 @@ AnimatorStateTransition:
|
|||
m_InterruptionSource: 0
|
||||
m_OrderedInterruption: 1
|
||||
m_CanTransitionToSelf: 1
|
||||
--- !u!1101 &-661908585856255301
|
||||
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: 0}
|
||||
m_Solo: 0
|
||||
m_Mute: 0
|
||||
m_IsExit: 1
|
||||
serializedVersion: 3
|
||||
m_TransitionDuration: 0.25
|
||||
m_TransitionOffset: 0
|
||||
m_ExitTime: 2
|
||||
m_HasExitTime: 1
|
||||
m_HasFixedDuration: 1
|
||||
m_InterruptionSource: 0
|
||||
m_OrderedInterruption: 1
|
||||
m_CanTransitionToSelf: 1
|
||||
--- !u!91 &9100000
|
||||
AnimatorController:
|
||||
m_ObjectHideFlags: 0
|
||||
|
@ -231,25 +253,25 @@ AnimatorController:
|
|||
m_DefaultFloat: 0
|
||||
m_DefaultInt: 0
|
||||
m_DefaultBool: 0
|
||||
m_Controller: {fileID: 0}
|
||||
m_Controller: {fileID: 9100000}
|
||||
- m_Name: EnemyInAggroRange
|
||||
m_Type: 4
|
||||
m_DefaultFloat: 0
|
||||
m_DefaultInt: 0
|
||||
m_DefaultBool: 0
|
||||
m_Controller: {fileID: 0}
|
||||
m_Controller: {fileID: 9100000}
|
||||
- m_Name: EnemyInAttackRange
|
||||
m_Type: 4
|
||||
m_DefaultFloat: 0
|
||||
m_DefaultInt: 0
|
||||
m_DefaultBool: 0
|
||||
m_Controller: {fileID: 0}
|
||||
m_Controller: {fileID: 9100000}
|
||||
- m_Name: Wandering
|
||||
m_Type: 4
|
||||
m_DefaultFloat: 0
|
||||
m_DefaultInt: 0
|
||||
m_DefaultBool: 0
|
||||
m_Controller: {fileID: 0}
|
||||
m_Controller: {fileID: 9100000}
|
||||
m_AnimatorLayers:
|
||||
- serializedVersion: 5
|
||||
m_Name: Base Layer
|
||||
|
@ -860,8 +882,10 @@ AnimatorState:
|
|||
m_Name: Die
|
||||
m_Speed: 1
|
||||
m_CycleOffset: 0
|
||||
m_Transitions: []
|
||||
m_StateMachineBehaviours: []
|
||||
m_Transitions:
|
||||
- {fileID: -661908585856255301}
|
||||
m_StateMachineBehaviours:
|
||||
- {fileID: 7912422198382985104}
|
||||
m_Position: {x: 50, y: 50, z: 0}
|
||||
m_IKOnFeet: 0
|
||||
m_WriteDefaultValues: 1
|
||||
|
@ -1043,7 +1067,7 @@ AnimatorStateMachine:
|
|||
m_Position: {x: 670, y: 550, z: 0}
|
||||
- serializedVersion: 1
|
||||
m_State: {fileID: 1102835054974116572}
|
||||
m_Position: {x: 280, y: 500, z: 0}
|
||||
m_Position: {x: 40, y: 380, z: 0}
|
||||
- serializedVersion: 1
|
||||
m_State: {fileID: 8194647877007136643}
|
||||
m_Position: {x: 300, y: 220, z: 0}
|
||||
|
@ -1060,7 +1084,7 @@ AnimatorStateMachine:
|
|||
m_StateMachineBehaviours: []
|
||||
m_AnyStatePosition: {x: 50, y: 20, z: 0}
|
||||
m_EntryPosition: {x: 100, y: 150, z: 0}
|
||||
m_ExitPosition: {x: 90, y: 510, z: 0}
|
||||
m_ExitPosition: {x: 50, y: 440, z: 0}
|
||||
m_ParentStateMachinePosition: {x: 800, y: 20, z: 0}
|
||||
m_DefaultState: {fileID: 1102546605246812244}
|
||||
--- !u!1101 &4009614032068998235
|
||||
|
@ -1113,6 +1137,18 @@ AnimatorStateTransition:
|
|||
m_InterruptionSource: 0
|
||||
m_OrderedInterruption: 1
|
||||
m_CanTransitionToSelf: 1
|
||||
--- !u!114 &7912422198382985104
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 1
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 0}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: aa7306c35f4c27d4daefb1259633b9d0, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
--- !u!1102 &8194647877007136643
|
||||
AnimatorState:
|
||||
serializedVersion: 6
|
||||
|
|
|
@ -19,6 +19,8 @@ public class SlimeAI : MonoBehaviour
|
|||
private bool isRotatingRight = false;
|
||||
private bool isWalking = false;
|
||||
|
||||
private bool isAttacking = false;
|
||||
private float attackStartTime;
|
||||
//[SerializeField]
|
||||
//private UnityEvent onAttack;
|
||||
|
||||
|
@ -27,7 +29,7 @@ public class SlimeAI : MonoBehaviour
|
|||
{
|
||||
animator = GetComponent<Animator>();
|
||||
player = GameObject.FindWithTag("Player");
|
||||
HP = 10;
|
||||
HP = 0;
|
||||
|
||||
}
|
||||
|
||||
|
@ -35,6 +37,11 @@ public class SlimeAI : MonoBehaviour
|
|||
void Update()
|
||||
{
|
||||
playerDistance = Vector3.Distance(player.transform.position, transform.position);
|
||||
|
||||
if (HP <= 0)
|
||||
{
|
||||
animator.Play("Die");
|
||||
}
|
||||
if (playerDistance < 1.5) //Attack
|
||||
{
|
||||
animator.SetBool("Wandering", false);
|
||||
|
@ -42,6 +49,7 @@ public class SlimeAI : MonoBehaviour
|
|||
animator.SetBool("EnemyInAggroRange", true);
|
||||
animator.SetBool("EnemyInVisionRange", true);
|
||||
Rotate();
|
||||
Attack();
|
||||
}
|
||||
else if (playerDistance < 10) //Chase
|
||||
{
|
||||
|
@ -91,15 +99,7 @@ public class SlimeAI : MonoBehaviour
|
|||
animator.SetBool("Wandering", true);
|
||||
transform.position += transform.forward * moveSpeed * Time.deltaTime;
|
||||
}
|
||||
if (HP <= 0)
|
||||
{
|
||||
animator.SetBool("Dead", true);
|
||||
}
|
||||
if (animator.GetBool("DeathComplete"))
|
||||
{
|
||||
print("asd");
|
||||
Destroy(this.gameObject);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
@ -120,6 +120,29 @@ public class SlimeAI : MonoBehaviour
|
|||
{
|
||||
HP -= dmg;
|
||||
}
|
||||
|
||||
void Attack()
|
||||
{
|
||||
if (!isAttacking)
|
||||
{
|
||||
isAttacking = true;
|
||||
attackStartTime = Time.time;
|
||||
StartCoroutine(DelayedAttack());
|
||||
}
|
||||
else if (Time.time - attackStartTime > 0.833)
|
||||
{
|
||||
isAttacking = false;
|
||||
attackStartTime = 0.0f;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
IEnumerator DelayedAttack()
|
||||
{
|
||||
yield return new WaitForSeconds(0.2f);
|
||||
Debug.Log("Attack");
|
||||
//do attack e.g check for player in range/hit collider
|
||||
}
|
||||
|
||||
IEnumerator Wander()
|
||||
{
|
||||
|
|
|
@ -2,7 +2,7 @@ using System.Collections;
|
|||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class death : StateMachineBehaviour
|
||||
public class SlimeDeath : 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)
|
||||
|
@ -17,10 +17,10 @@ public class death : StateMachineBehaviour
|
|||
//}
|
||||
|
||||
// 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)
|
||||
//{
|
||||
//
|
||||
//}
|
||||
override public void OnStateExit(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
|
||||
{
|
||||
Destroy(animator.gameObject);
|
||||
}
|
||||
|
||||
// OnStateMove is called right after Animator.OnAnimatorMove()
|
||||
//override public void OnStateMove(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
|
|
@ -1,5 +1,5 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 6c7f89faf36f41b418e5105a12c34cdb
|
||||
guid: aa7306c35f4c27d4daefb1259633b9d0
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
Loading…
Reference in New Issue