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 // Start is called before the first frame update
36 //Hier wird der Rigidbody initialisiert
37 rb = GetComponent<Rigidbody2D>();
39 powerUps = GetComponent<PowerUps>();
42 // Update is called once per frame
45 if(isGrounded == true && Input.GetButtonDown("Jump"))
48 jumpTimeCounter = jumptime;
49 rb.velocity = Vector2.up * jumpForce;
52 if (Input.GetButton("Jump") && isJumping == true)
54 if(jumpTimeCounter > 0)
56 rb.velocity = Vector2.up * jumpForce;
57 jumpTimeCounter -= Time.deltaTime;
58 FindObjectOfType<AudioManager>().Play("sprung");
62 if (Input.GetButtonUp("Jump"))
67 if (rb.velocity.x < 0)
69 transform.localScale = new Vector3(-1, 1, 1);
72 else if (rb.velocity.x > 0)
74 transform.localScale = new Vector3(1, 1, 1);
78 if(powerUps.mouseIsGardener == true)
80 if (Input.GetButtonDown("Fire1"))
82 if (isShooting) return;
86 GameObject b = Instantiate(bullet);
87 b.GetComponent<Scissors>().StartShoot(isFacingLeft);
88 b.transform.position = bulletSpawnPos.transform.position;
90 Invoke("ResetShoot", shootDelay);
94 moveInput = Input.GetAxisRaw("Horizontal");
99 //Hier wird ein Kreis unter der Maus erzeugt, der prüft, ob die Maus den Boden berührt
100 isGrounded = Physics2D.OverlapCircle(groundcheck.position, checkRadius, whatIsGround);
102 //Wenn a und d oder Pfeiltaste links und rechts gedrückt werden, ist der Wert von moveInput -1 oder 1;
103 rb.velocity = new Vector2(moveInput * speed, rb.velocity.y);