1 //Mit diesem Script kann man die Maus steuern.
3 using System.Collections;
4 using System.Collections.Generic;
7 public class MouseController : MonoBehaviour
11 public float jumpForce;
12 private float jumpTimeCounter;
13 public float jumptime;
14 private bool isJumping;
15 private float moveInput;
17 private bool isGrounded;
18 public Transform groundcheck;
19 public float checkRadius;
20 public LayerMask whatIsGround;
24 public bool isFacingLeft;
26 private bool isShooting;
31 Transform bulletSpawnPos;
33 private float shootDelay = 0.5f;
35 // Start is called before the first frame update
38 //Hier wird der Rigidbody initialisiert
39 rb = GetComponent<Rigidbody2D>();
41 powerUps = GetComponent<PowerUps>();
44 // Update is called once per frame
47 if (isGrounded == true && Input.GetButtonDown("Jump"))
50 jumpTimeCounter = jumptime;
51 rb.velocity = new Vector2(rb.velocity.x, jumpForce);
54 if (Input.GetButton("Jump") && isJumping == true)
56 if (jumpTimeCounter > 0)
58 rb.velocity = new Vector2(rb.velocity.x, jumpForce);
59 jumpTimeCounter -= Time.deltaTime;
60 FindObjectOfType<AudioManager>().Play("sprung");
64 if (Input.GetButtonUp("Jump"))
69 if (rb.velocity.x < 0)
71 transform.localScale = new Vector3(-1, 1, 1);
74 else if (rb.velocity.x > 0)
76 transform.localScale = new Vector3(1, 1, 1);
80 if (powerUps.mouseIsGardener == true)
82 if (Input.GetButtonDown("Fire1") && ! isShooting)
86 GameObject b = Instantiate(bullet);
87 b.GetComponent<Scissors>().StartShoot(isFacingLeft, rb.velocity);
88 b.transform.position = bulletSpawnPos.transform.position;
90 Invoke("ResetShoot", shootDelay);
94 moveInput = Input.GetAxisRaw("Horizontal");
97 bool HasReachedTV(float acceleration)
101 if (rb.velocity.x <= -speed)
104 else if (acceleration > 0)
106 if (rb.velocity.x >= speed)
115 //Hier wird ein Kreis unter der Maus erzeugt, der prueft, ob die Maus den Boden beruehrt
116 isGrounded = Physics2D.OverlapCircle(groundcheck.position, checkRadius, whatIsGround);
118 //Wenn a und d oder Pfeiltaste links und rechts gedrueckt werden, ist der Wert von moveInput -1 oder 1;
120 float acceleration = speed;
124 acceleration *= moveInput * 4;
128 acceleration *= -Math.Sign(rb.velocity.x) * 16;
135 if (! HasReachedTV(acceleration))
137 int oldSign = Math.Sign(rb.velocity.x);
138 rb.velocity += new Vector2(acceleration * Time.fixedDeltaTime, 0);
140 if (HasReachedTV(acceleration))
141 rb.velocity = new Vector2(Math.Sign(rb.velocity.x) * speed, rb.velocity.y);
142 if (oldSign == -Math.Sign(rb.velocity.x))
143 rb.velocity = new Vector2(0, rb.velocity.y);