]> git.lizzy.rs Git - SuperMouseAdventure.git/blob - 2DGame/Assets/Scripts/Enemies/Boss/BossMovement.cs
Dialog-System 0.4
[SuperMouseAdventure.git] / 2DGame / Assets / Scripts / Enemies / Boss / BossMovement.cs
1 using System.Collections;
2 using System.Collections.Generic;
3 using UnityEngine;
4
5 public class BossMovement : StateMachineBehaviour
6 {   
7     FollowPlayer fp;
8     Boss boss;
9
10     // OnStateEnter is called when a transition starts and the state machine starts to evaluate this state
11     override public void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
12     {
13         fp = animator.GetComponent<FollowPlayer>();
14         boss = animator.GetComponent<Boss>();
15     }
16
17     // OnStateUpdate is called on each Update frame between OnStateEnter and OnStateExit callbacks
18     override public void OnStateUpdate(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
19     {
20         if (boss.bossfight)
21         {
22             if (fp.distToPlayer < fp.agroRange - 20)
23             {
24                 animator.SetBool("Idle", false);
25                 animator.SetBool("Attack", true);
26             }
27             else if (fp.distToPlayer > fp.agroRange)
28             {
29                 animator.SetBool("Idle", true);
30                 animator.SetBool("Attack", false);
31             }
32         }
33         else
34         {
35             animator.SetBool("Idle", true);
36             animator.SetBool("Attack", false);
37         }
38     }
39
40     // OnStateExit is called when a transition ends and the state machine finishes evaluating this state
41     override public void OnStateExit(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
42     {
43         animator.SetBool("Attack", false);
44         animator.SetBool("Idle", false);
45     }
46 }