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;
20 private int extraJumps;
21 public int extraJumpsValue;
25 public bool isFacingLeft;
27 private Animation anim;
28 private bool isShooting;
30 private Object bulletRef;
34 Transform bulletSpawnPos;
36 private float shootDelay = 0.5f;
38 // Start is called before the first frame update
41 extraJumps = extraJumpsValue;
43 //Hier wird der Rigidbody initialisiert
44 rb = GetComponent<Rigidbody2D>();
46 anim = GetComponent<Animation>();
48 powerUps = GetComponent<PowerUps>();
51 // Update is called once per frame
54 if(isGrounded == true)
56 extraJumps = extraJumpsValue;
59 if(isGrounded == true && Input.GetButtonDown("Jump"))
62 jumpTimeCounter = jumptime;
63 rb.velocity = Vector2.up * jumpForce;
66 if (Input.GetButton("Jump") && isJumping == true && extraJumps > 0)
68 if(jumpTimeCounter > 0)
70 rb.velocity = Vector2.up * jumpForce;
71 jumpTimeCounter -= Time.deltaTime;
72 FindObjectOfType<AudioManager>().Play("sprung");
76 else if (Input.GetButton("Jump") && extraJumps == 0)
78 if (jumpTimeCounter > 0)
80 rb.velocity = Vector2.up * jumpForce;
81 jumpTimeCounter -= Time.deltaTime;
82 FindObjectOfType<AudioManager>().Play("sprung");
90 if (Input.GetButtonUp("Jump"))
95 if (rb.velocity.x < 0)
97 transform.localScale = new Vector3(-1, 1, 1);
100 else if (rb.velocity.x > 0)
102 transform.localScale = new Vector3(1, 1, 1);
103 isFacingLeft = false;
106 if(powerUps.mouseIsGardener == true)
108 if (Input.GetButtonDown("Fire1"))
110 if (isShooting) return;
114 GameObject b = Instantiate(bullet);
115 b.GetComponent<Scissors>().StartShoot(isFacingLeft);
116 b.transform.position = bulletSpawnPos.transform.position;
118 Invoke("ResetShoot", shootDelay);
125 //Hier wird ein Kreis unter der Maus erzeugt, der prüft, ob die Maus den Boden berührt
126 isGrounded = Physics2D.OverlapCircle(groundcheck.position, checkRadius, whatIsGround);
128 //Wenn a und d oder Pfeiltaste links und rechts gedrückt werden, ist der Wert von moveInput -1 oder 1;
129 moveInput = Input.GetAxisRaw("Horizontal");
130 rb.velocity = new Vector2(moveInput * speed, rb.velocity.y);