fixes to slime death, attack function has proper timings
This commit is contained in:
@@ -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()
|
||||
{
|
||||
|
||||
@@ -1,36 +0,0 @@
|
||||
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)
|
||||
//}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6c7f89faf36f41b418e5105a12c34cdb
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user