using UnityEngine;
public class BossMovement : StateMachineBehaviour
-{
- public float speed = 4.5f;
- public float attackRange = 22f;
-
- Transform player;
- Rigidbody2D rb;
+{
+ FollowPlayer fp;
// 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)
{
- player = GameObject.FindGameObjectWithTag("Player").transform;
- rb = animator.GetComponent<Rigidbody2D>();
+ fp = animator.GetComponent<FollowPlayer>();
}
// OnStateUpdate is called on each Update frame between OnStateEnter and OnStateExit callbacks
override public void OnStateUpdate(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
{
- Debug.Log(Vector2.Distance(rb.position, player.position));
-
- if (Vector2.Distance(rb.position, player.position) <= attackRange)
+ if (fp.distToPlayer < fp.agroRange - 20)
{
animator.SetTrigger("Attack");
}
[SerializeField]
Transform player;
- [SerializeField]
- private float agroRange;
+ public float agroRange;
[SerializeField]
private float MoveSpeed;
+ public float distToPlayer;
+
Rigidbody2D rb;
// Start is called before the first frame update
void Update()
{
//Abstand zur Spielfigur
- float distToPlayer = Vector2.Distance(transform.position, player.position);
+ distToPlayer = Vector2.Distance(transform.position, player.position);
if(distToPlayer < agroRange)
{
{
StopChasingPlayer();
}
-
}
void ChasePlayer()
"com.unity.textmeshpro": "3.0.1",
"com.unity.timeline": "1.4.6",
"com.unity.toolchain.macos-x86_64-linux-x86_64": "0.1.21-preview",
- "com.unity.toolchain.win-x86_64-linux-x86_64": "0.1.20-preview",
+ "com.unity.toolchain.win-x86_64-linux-x86_64": "0.1.21-preview",
"com.unity.ugui": "1.0.0",
"com.unity.modules.ai": "1.0.0",
"com.unity.modules.androidjni": "1.0.0",
"url": "https://packages.unity.com"
},
"com.unity.toolchain.win-x86_64-linux-x86_64": {
- "version": "0.1.20-preview",
+ "version": "0.1.21-preview",
"depth": 0,
"source": "registry",
"dependencies": {