]> git.lizzy.rs Git - SuperMouseAdventure.git/commitdiff
Schnecke verhält sich wie gewollt
authorKG0104 <76601263+KG0104@users.noreply.github.com>
Thu, 22 Jul 2021 16:29:01 +0000 (18:29 +0200)
committerKG0104 <76601263+KG0104@users.noreply.github.com>
Thu, 22 Jul 2021 16:29:01 +0000 (18:29 +0200)
Nun verfolgt die Schnecke die Maus und greift sie an

2DGame/Assets/Scripts/Gegner/Boss/BossMovement.cs
2DGame/Assets/Scripts/Gegner/FollowPlayer.cs
2DGame/Packages/manifest.json
2DGame/Packages/packages-lock.json

index 2cb6d62749dd14e8ac7c8291b0f5bbbbb3c7ece4..7c6325ef1179c736af987d381566d486609b9d3c 100644 (file)
@@ -3,26 +3,19 @@ using System.Collections.Generic;
 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");
         }
index 13fe9c0b66e916ec1ee9227b27d65e0a025dd6ac..d17e1db049040921abbcf6c0e39fd878867c1b79 100644 (file)
@@ -10,12 +10,13 @@ public class FollowPlayer : MonoBehaviour
     [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
@@ -28,7 +29,7 @@ public class FollowPlayer : MonoBehaviour
     void Update()
     {
         //Abstand zur Spielfigur
-        float distToPlayer = Vector2.Distance(transform.position, player.position);
+        distToPlayer = Vector2.Distance(transform.position, player.position);
 
         if(distToPlayer < agroRange)
         {
@@ -37,7 +38,6 @@ public class FollowPlayer : MonoBehaviour
         {
             StopChasingPlayer();
         }
-
     }
 
     void ChasePlayer()
index 31c0c6dd62f82d85dc690662be1f61b19f059fb6..bab226d5e61c7761fc8cd388e7d336324b8977b1 100644 (file)
@@ -11,7 +11,7 @@
     "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",
index 67bc226e215e51e157edf2ca19735efb5791a08a..7583bbf4b6d9a4bca92b2505ceda94bf9768c17f 100644 (file)
       "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": {