to master merge

This commit is contained in:
2022-05-02 16:09:20 +03:00
parent 6571056d18
commit 2beb3298c6
10 changed files with 138 additions and 117 deletions

View File

@@ -19,8 +19,10 @@ public class SlimeAI : MonoBehaviour
private bool isRotatingRight = false;
private bool isWalking = false;
public UnityEvent onDeathComplete;
private bool isAttacking = false;
private float attackStartTime;
public UnityEvent onDeathComplete;
//[SerializeField]
//private UnityEvent onAttack;
@@ -29,14 +31,20 @@ public class SlimeAI : MonoBehaviour
{
animator = GetComponent<Animator>();
player = GameObject.FindWithTag("Player");
HP = 2;
HP = 0;
}
// Update is called once per frame
void Update()
{
playerDistance = Vector3.Distance(player.transform.position, transform.position);
if (HP <= 0)
{
animator.Play("Die");
onDeathComplete.Invoke();
}
if (playerDistance < 1.5) //Attack
{
animator.SetBool("Wandering", false);
@@ -44,6 +52,7 @@ public class SlimeAI : MonoBehaviour
animator.SetBool("EnemyInAggroRange", true);
animator.SetBool("EnemyInVisionRange", true);
Rotate();
Attack();
}
else if (playerDistance < 10) //Chase
{
@@ -69,12 +78,15 @@ public class SlimeAI : MonoBehaviour
animator.SetBool("EnemyInAggroRange", false);
animator.SetBool("EnemyInVisionRange", false);
}
if (!isWandering)
{
//Idle
StartCoroutine("Wander");
}
Debug.Log(isWandering);
Debug.Log(isRotatingLeft);
Debug.Log(isRotatingRight);
if (isRotatingRight == true)
{
animator.SetBool("Wandering", false);
@@ -90,18 +102,6 @@ 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("Dead"))
{
print("asd");
Destroy(this.gameObject);
onDeathComplete.Invoke();
}
@@ -124,6 +124,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()
{
int rotTime = Random.Range(1, 3);
@@ -154,4 +177,4 @@ public class SlimeAI : MonoBehaviour
isWandering = false;
}
}
}