From a8c8a9ae208ab41c58f4d18de0831e09b8718571 Mon Sep 17 00:00:00 2001 From: Elias Fleckenstein Date: Wed, 11 Aug 2021 19:02:28 +0200 Subject: [PATCH] =?utf8?q?Scheren=20=C3=BCbernehmen=20Bewegung=20der=20Mau?= =?utf8?q?s?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- 2DGame/Assets/Prefabs/schere.prefab | 4 +- 2DGame/Assets/Scripts/Gegner/EnemyScript.cs | 2 +- 2DGame/Assets/Scripts/Maus/MouseController.cs | 40 +++++++++---------- 2DGame/Assets/Scripts/Maus/Scissors.cs | 17 +++++--- 4 files changed, 33 insertions(+), 30 deletions(-) diff --git a/2DGame/Assets/Prefabs/schere.prefab b/2DGame/Assets/Prefabs/schere.prefab index f1ca607..eefbbb4 100644 --- a/2DGame/Assets/Prefabs/schere.prefab +++ b/2DGame/Assets/Prefabs/schere.prefab @@ -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 diff --git a/2DGame/Assets/Scripts/Gegner/EnemyScript.cs b/2DGame/Assets/Scripts/Gegner/EnemyScript.cs index e34a884..2964747 100644 --- a/2DGame/Assets/Scripts/Gegner/EnemyScript.cs +++ b/2DGame/Assets/Scripts/Gegner/EnemyScript.cs @@ -12,7 +12,7 @@ public class EnemyScript : MonoBehaviour { if (enemyHealth <= 0) { - Destroy(gameObject); + gameObject.SetActive(false); } } diff --git a/2DGame/Assets/Scripts/Maus/MouseController.cs b/2DGame/Assets/Scripts/Maus/MouseController.cs index b09c44f..0731077 100644 --- a/2DGame/Assets/Scripts/Maus/MouseController.cs +++ b/2DGame/Assets/Scripts/Maus/MouseController.cs @@ -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().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().StartShoot(isFacingLeft); + b.GetComponent().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().Play("sprung"); - } - } } void ResetShoot() diff --git a/2DGame/Assets/Scripts/Maus/Scissors.cs b/2DGame/Assets/Scripts/Maus/Scissors.cs index 0908958..0044202 100644 --- a/2DGame/Assets/Scripts/Maus/Scissors.cs +++ b/2DGame/Assets/Scripts/Maus/Scissors.cs @@ -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(); - 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); } } -- 2.44.0