1 //Mit diesem Script kann man die Maus steuern.
2 using System.Collections;
3 using System.Collections.Generic;
5 public class MouseController : MonoBehaviour
9 public float jumpForce;
10 private float jumpTimeCounter;
11 public float jumptime;
12 private bool isJumping;
13 private float moveInput;
15 private bool isGrounded;
16 public Transform groundcheck;
17 public float checkRadius;
18 public LayerMask whatIsGround;
22 public bool isFacingLeft;
24 private bool isShooting;
29 Transform bulletSpawnPos;
31 private float shootDelay = 0.5f;
33 Checkpoint checkpoint;
35 // Start is called before the first frame update
38 //Hier wird der Rigidbody initialisiert
39 rb = GetComponent<Rigidbody2D>();
41 powerUps = GetComponent<PowerUps>();
43 checkpoint = GetComponent<Checkpoint>();
45 transform.position = checkpoint.CheckPoints[3].transform.position;
48 // Update is called once per frame
51 if(isGrounded == true && Input.GetButtonDown("Jump"))
54 jumpTimeCounter = jumptime;
55 rb.velocity = Vector2.up * jumpForce;
58 if (Input.GetButton("Jump") && isJumping == true)
60 if(jumpTimeCounter > 0)
62 rb.velocity = Vector2.up * jumpForce;
63 jumpTimeCounter -= Time.deltaTime;
64 FindObjectOfType<AudioManager>().Play("sprung");
68 if (Input.GetButtonUp("Jump"))
73 if (rb.velocity.x < 0)
75 transform.localScale = new Vector3(-1, 1, 1);
78 else if (rb.velocity.x > 0)
80 transform.localScale = new Vector3(1, 1, 1);
84 if(powerUps.mouseIsGardener == true)
86 if (Input.GetButtonDown("Fire1"))
88 if (isShooting) return;
92 GameObject b = Instantiate(bullet);
93 b.GetComponent<Scissors>().StartShoot(isFacingLeft);
94 b.transform.position = bulletSpawnPos.transform.position;
96 Invoke("ResetShoot", shootDelay);
100 moveInput = Input.GetAxisRaw("Horizontal");
110 //Hier wird ein Kreis unter der Maus erzeugt, der prüft, ob die Maus den Boden berührt
111 isGrounded = Physics2D.OverlapCircle(groundcheck.position, checkRadius, whatIsGround);
113 //Wenn a und d oder Pfeiltaste links und rechts gedrückt werden, ist der Wert von moveInput -1 oder 1;
114 rb.velocity = new Vector2(moveInput * speed, rb.velocity.y);