]> git.lizzy.rs Git - SuperMouseAdventure.git/commitdiff
Scheren übernehmen Bewegung der Maus
authorElias Fleckenstein <eliasfleckenstein@web.de>
Wed, 11 Aug 2021 17:02:28 +0000 (19:02 +0200)
committerElias Fleckenstein <eliasfleckenstein@web.de>
Wed, 11 Aug 2021 17:02:28 +0000 (19:02 +0200)
2DGame/Assets/Prefabs/schere.prefab
2DGame/Assets/Scripts/Gegner/EnemyScript.cs
2DGame/Assets/Scripts/Maus/MouseController.cs
2DGame/Assets/Scripts/Maus/Scissors.cs

index f1ca6073dcf63b5ffc27bd96f61ffb3a698dbbbb..eefbbb42cef668fcc987c16c59ce4ad86a9325ab 100644 (file)
@@ -100,12 +100,12 @@ Rigidbody2D:
   m_Mass: 1
   m_LinearDrag: 0
   m_AngularDrag: 0.05
-  m_GravityScale: 1
+  m_GravityScale: 0
   m_Material: {fileID: 0}
   m_Interpolate: 0
   m_SleepingMode: 1
   m_CollisionDetection: 0
-  m_Constraints: 6
+  m_Constraints: 4
 --- !u!61 &6820967811485032814
 BoxCollider2D:
   m_ObjectHideFlags: 0
index e34a8849e2d8a5cbcc3b3f25168fcd74263e16be..2964747c52af12959cc785708454bef9c2fcba2c 100644 (file)
@@ -12,7 +12,7 @@ public class EnemyScript : MonoBehaviour
     {
         if (enemyHealth <= 0)
         {
-            Destroy(gameObject);
+            gameObject.SetActive(false);
         }
     }
 
index b09c44fe978be5319d42ca71308a7ca1622d8e6f..07310774b4e1370b63e64d47999260c2c9aaca5a 100644 (file)
@@ -43,6 +43,23 @@ public class MouseController : MonoBehaviour
     // Update is called once per frame
     void Update()
     {
+               if (isGrounded == true && Input.GetButtonDown("Jump"))
+        {
+            isJumping = true;
+            jumpTimeCounter = jumptime;
+            rb.velocity = new Vector2(rb.velocity.x, jumpForce);
+        }
+
+        if (Input.GetButton("Jump") && isJumping == true)
+        {
+            if (jumpTimeCounter > 0)
+            {
+                rb.velocity = new Vector2(rb.velocity.x, jumpForce);
+                jumpTimeCounter -= Time.deltaTime;
+                FindObjectOfType<AudioManager>().Play("sprung");
+            }
+        }
+
         if (Input.GetButtonUp("Jump"))
         {
             isJumping = false;
@@ -61,14 +78,12 @@ public class MouseController : MonoBehaviour
 
         if (powerUps.mouseIsGardener == true)
         {
-            if (Input.GetButtonDown("Fire1"))
+            if (Input.GetButtonDown("Fire1") && ! isShooting)
             {
-                if (isShooting) return;
-
                 isShooting = true;
 
                 GameObject b = Instantiate(bullet);
-                b.GetComponent<Scissors>().StartShoot(isFacingLeft);
+                b.GetComponent<Scissors>().StartShoot(isFacingLeft, rb.velocity);
                 b.transform.position = bulletSpawnPos.transform.position;
 
                 Invoke("ResetShoot", shootDelay);
@@ -126,23 +141,6 @@ public class MouseController : MonoBehaviour
                        if (oldSign == -Math.Sign(rb.velocity.x))
                                rb.velocity = new Vector2(0, rb.velocity.y);
                }
-
-        if (isGrounded == true && Input.GetButtonDown("Jump"))
-        {
-            isJumping = true;
-            jumpTimeCounter = jumptime;
-            rb.velocity = new Vector2(rb.velocity.x, jumpForce);
-        }
-
-        if (Input.GetButton("Jump") && isJumping == true)
-        {
-            if (jumpTimeCounter > 0)
-            {
-                rb.velocity = new Vector2(rb.velocity.x, jumpForce);
-                jumpTimeCounter -= Time.fixedDeltaTime;
-                FindObjectOfType<AudioManager>().Play("sprung");
-            }
-        }
     }
 
     void ResetShoot()
index 09089586a15701cb5ba5847777634ea389f6d9b3..0044202017c8abcb6607649baf705b8a058170c5 100644 (file)
@@ -1,3 +1,4 @@
+using System;
 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
@@ -10,20 +11,24 @@ public class Scissors : MonoBehaviour
     [SerializeField]
     float lifeTime = 10;
 
-    public void StartShoot(bool isFacingLeft)
+    public void StartShoot(bool isFacingLeft, Vector2 velocity)
     {
         Rigidbody2D rb2d = GetComponent<Rigidbody2D>();
-        if(isFacingLeft == true)
+        transform.localScale = new Vector3(0.4f, 0.4f, 1);
+
+        if (isFacingLeft == true)
         {
-            rb2d.velocity = new Vector2(-speed, 0);
-            transform.localScale = new Vector3(-0.4f, 0.4f, 1);
+            rb2d.velocity = new Vector2(-speed, 0) + velocity;
         }
         else
         {
-            rb2d.velocity = new Vector2(speed, 0);
-            transform.localScale = new Vector3(0.4f, 0.4f, 1);
+            rb2d.velocity = new Vector2(speed, 0) + velocity;
         }
 
+        Vector2 movementDirection = rb2d.velocity;
+               movementDirection.Normalize();
+               transform.rotation = Quaternion.LookRotation(Vector3.forward, movementDirection) * Quaternion.Euler(0, 0, 90);
+
         Destroy(gameObject, lifeTime);
     }
 }