fixes to slime death, attack function has proper timings #35
|
@ -217,6 +217,28 @@ AnimatorStateTransition:
|
||||||
m_InterruptionSource: 0
|
m_InterruptionSource: 0
|
||||||
m_OrderedInterruption: 1
|
m_OrderedInterruption: 1
|
||||||
m_CanTransitionToSelf: 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
|
--- !u!91 &9100000
|
||||||
AnimatorController:
|
AnimatorController:
|
||||||
m_ObjectHideFlags: 0
|
m_ObjectHideFlags: 0
|
||||||
|
@ -231,25 +253,25 @@ AnimatorController:
|
||||||
m_DefaultFloat: 0
|
m_DefaultFloat: 0
|
||||||
m_DefaultInt: 0
|
m_DefaultInt: 0
|
||||||
m_DefaultBool: 0
|
m_DefaultBool: 0
|
||||||
m_Controller: {fileID: 0}
|
m_Controller: {fileID: 9100000}
|
||||||
- m_Name: EnemyInAggroRange
|
- m_Name: EnemyInAggroRange
|
||||||
m_Type: 4
|
m_Type: 4
|
||||||
m_DefaultFloat: 0
|
m_DefaultFloat: 0
|
||||||
m_DefaultInt: 0
|
m_DefaultInt: 0
|
||||||
m_DefaultBool: 0
|
m_DefaultBool: 0
|
||||||
m_Controller: {fileID: 0}
|
m_Controller: {fileID: 9100000}
|
||||||
- m_Name: EnemyInAttackRange
|
- m_Name: EnemyInAttackRange
|
||||||
m_Type: 4
|
m_Type: 4
|
||||||
m_DefaultFloat: 0
|
m_DefaultFloat: 0
|
||||||
m_DefaultInt: 0
|
m_DefaultInt: 0
|
||||||
m_DefaultBool: 0
|
m_DefaultBool: 0
|
||||||
m_Controller: {fileID: 0}
|
m_Controller: {fileID: 9100000}
|
||||||
- m_Name: Wandering
|
- m_Name: Wandering
|
||||||
m_Type: 4
|
m_Type: 4
|
||||||
m_DefaultFloat: 0
|
m_DefaultFloat: 0
|
||||||
m_DefaultInt: 0
|
m_DefaultInt: 0
|
||||||
m_DefaultBool: 0
|
m_DefaultBool: 0
|
||||||
m_Controller: {fileID: 0}
|
m_Controller: {fileID: 9100000}
|
||||||
m_AnimatorLayers:
|
m_AnimatorLayers:
|
||||||
- serializedVersion: 5
|
- serializedVersion: 5
|
||||||
m_Name: Base Layer
|
m_Name: Base Layer
|
||||||
|
@ -860,8 +882,10 @@ AnimatorState:
|
||||||
m_Name: Die
|
m_Name: Die
|
||||||
m_Speed: 1
|
m_Speed: 1
|
||||||
m_CycleOffset: 0
|
m_CycleOffset: 0
|
||||||
m_Transitions: []
|
m_Transitions:
|
||||||
m_StateMachineBehaviours: []
|
- {fileID: -661908585856255301}
|
||||||
|
m_StateMachineBehaviours:
|
||||||
|
- {fileID: 7912422198382985104}
|
||||||
m_Position: {x: 50, y: 50, z: 0}
|
m_Position: {x: 50, y: 50, z: 0}
|
||||||
m_IKOnFeet: 0
|
m_IKOnFeet: 0
|
||||||
m_WriteDefaultValues: 1
|
m_WriteDefaultValues: 1
|
||||||
|
@ -1043,7 +1067,7 @@ AnimatorStateMachine:
|
||||||
m_Position: {x: 670, y: 550, z: 0}
|
m_Position: {x: 670, y: 550, z: 0}
|
||||||
- serializedVersion: 1
|
- serializedVersion: 1
|
||||||
m_State: {fileID: 1102835054974116572}
|
m_State: {fileID: 1102835054974116572}
|
||||||
m_Position: {x: 280, y: 500, z: 0}
|
m_Position: {x: 40, y: 380, z: 0}
|
||||||
- serializedVersion: 1
|
- serializedVersion: 1
|
||||||
m_State: {fileID: 8194647877007136643}
|
m_State: {fileID: 8194647877007136643}
|
||||||
m_Position: {x: 300, y: 220, z: 0}
|
m_Position: {x: 300, y: 220, z: 0}
|
||||||
|
@ -1060,7 +1084,7 @@ AnimatorStateMachine:
|
||||||
m_StateMachineBehaviours: []
|
m_StateMachineBehaviours: []
|
||||||
m_AnyStatePosition: {x: 50, y: 20, z: 0}
|
m_AnyStatePosition: {x: 50, y: 20, z: 0}
|
||||||
m_EntryPosition: {x: 100, y: 150, 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_ParentStateMachinePosition: {x: 800, y: 20, z: 0}
|
||||||
m_DefaultState: {fileID: 1102546605246812244}
|
m_DefaultState: {fileID: 1102546605246812244}
|
||||||
--- !u!1101 &4009614032068998235
|
--- !u!1101 &4009614032068998235
|
||||||
|
@ -1113,6 +1137,18 @@ AnimatorStateTransition:
|
||||||
m_InterruptionSource: 0
|
m_InterruptionSource: 0
|
||||||
m_OrderedInterruption: 1
|
m_OrderedInterruption: 1
|
||||||
m_CanTransitionToSelf: 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
|
--- !u!1102 &8194647877007136643
|
||||||
AnimatorState:
|
AnimatorState:
|
||||||
serializedVersion: 6
|
serializedVersion: 6
|
||||||
|
|
|
@ -19,6 +19,8 @@ public class SlimeAI : MonoBehaviour
|
||||||
private bool isRotatingRight = false;
|
private bool isRotatingRight = false;
|
||||||
private bool isWalking = false;
|
private bool isWalking = false;
|
||||||
|
|
||||||
|
private bool isAttacking = false;
|
||||||
|
private float attackStartTime;
|
||||||
//[SerializeField]
|
//[SerializeField]
|
||||||
//private UnityEvent onAttack;
|
//private UnityEvent onAttack;
|
||||||
|
|
||||||
|
@ -27,7 +29,7 @@ public class SlimeAI : MonoBehaviour
|
||||||
{
|
{
|
||||||
animator = GetComponent<Animator>();
|
animator = GetComponent<Animator>();
|
||||||
player = GameObject.FindWithTag("Player");
|
player = GameObject.FindWithTag("Player");
|
||||||
HP = 10;
|
HP = 0;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -35,6 +37,11 @@ public class SlimeAI : MonoBehaviour
|
||||||
void Update()
|
void Update()
|
||||||
{
|
{
|
||||||
playerDistance = Vector3.Distance(player.transform.position, transform.position);
|
playerDistance = Vector3.Distance(player.transform.position, transform.position);
|
||||||
|
|
||||||
|
if (HP <= 0)
|
||||||
|
{
|
||||||
|
animator.Play("Die");
|
||||||
|
}
|
||||||
if (playerDistance < 1.5) //Attack
|
if (playerDistance < 1.5) //Attack
|
||||||
{
|
{
|
||||||
animator.SetBool("Wandering", false);
|
animator.SetBool("Wandering", false);
|
||||||
|
@ -42,6 +49,7 @@ public class SlimeAI : MonoBehaviour
|
||||||
animator.SetBool("EnemyInAggroRange", true);
|
animator.SetBool("EnemyInAggroRange", true);
|
||||||
animator.SetBool("EnemyInVisionRange", true);
|
animator.SetBool("EnemyInVisionRange", true);
|
||||||
Rotate();
|
Rotate();
|
||||||
|
Attack();
|
||||||
}
|
}
|
||||||
else if (playerDistance < 10) //Chase
|
else if (playerDistance < 10) //Chase
|
||||||
{
|
{
|
||||||
|
@ -91,15 +99,7 @@ public class SlimeAI : MonoBehaviour
|
||||||
animator.SetBool("Wandering", true);
|
animator.SetBool("Wandering", true);
|
||||||
transform.position += transform.forward * moveSpeed * Time.deltaTime;
|
transform.position += transform.forward * moveSpeed * Time.deltaTime;
|
||||||
}
|
}
|
||||||
if (HP <= 0)
|
|
||||||
{
|
|
||||||
animator.SetBool("Dead", true);
|
|
||||||
}
|
|
||||||
if (animator.GetBool("DeathComplete"))
|
|
||||||
{
|
|
||||||
print("asd");
|
|
||||||
Destroy(this.gameObject);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -121,6 +121,29 @@ public class SlimeAI : MonoBehaviour
|
||||||
HP -= dmg;
|
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()
|
IEnumerator Wander()
|
||||||
{
|
{
|
||||||
int rotTime = Random.Range(1, 3);
|
int rotTime = Random.Range(1, 3);
|
||||||
|
|
|
@ -2,7 +2,7 @@ using System.Collections;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using UnityEngine;
|
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
|
// 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)
|
//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
|
// 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()
|
// OnStateMove is called right after Animator.OnAnimatorMove()
|
||||||
//override public void OnStateMove(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
|
//override public void OnStateMove(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
|
|
@ -1,5 +1,5 @@
|
||||||
fileFormatVersion: 2
|
fileFormatVersion: 2
|
||||||
guid: 6c7f89faf36f41b418e5105a12c34cdb
|
guid: aa7306c35f4c27d4daefb1259633b9d0
|
||||||
MonoImporter:
|
MonoImporter:
|
||||||
externalObjects: {}
|
externalObjects: {}
|
||||||
serializedVersion: 2
|
serializedVersion: 2
|
Loading…
Reference in New Issue