1 //Mit diesem Script kann man die Maus steuern.
3 using System.Collections;
4 using System.Collections.Generic;
6 public class MouseController : MonoBehaviour
10 public float jumpForce;
11 private float jumpTimeCounter;
12 public float jumptime;
13 private bool isJumping;
14 private float moveInput;
16 private bool isGrounded;
17 public Transform groundcheck;
18 public float checkRadius;
19 public LayerMask whatIsGround;
23 public bool isFacingLeft;
25 private bool isShooting;
30 Transform bulletSpawnPos;
32 private float shootDelay = 0.5f;
34 // Start is called before the first frame update
37 //Hier wird der Rigidbody initialisiert
38 rb = GetComponent<Rigidbody2D>();
40 powerUps = GetComponent<PowerUps>();
43 // Update is called once per frame
46 if (Input.GetButtonUp("Jump"))
51 if (rb.velocity.x < 0)
53 transform.localScale = new Vector3(-1, 1, 1);
56 else if (rb.velocity.x > 0)
58 transform.localScale = new Vector3(1, 1, 1);
62 if (powerUps.mouseIsGardener == true)
64 if (Input.GetButtonDown("Fire1"))
66 if (isShooting) return;
70 GameObject b = Instantiate(bullet);
71 b.GetComponent<Scissors>().StartShoot(isFacingLeft);
72 b.transform.position = bulletSpawnPos.transform.position;
74 Invoke("ResetShoot", shootDelay);
78 moveInput = Input.GetAxisRaw("Horizontal");
81 bool HasReachedTV(float acceleration)
85 if (rb.velocity.x <= -speed)
88 else if (acceleration > 0)
90 if (rb.velocity.x >= speed)
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;
104 float acceleration = speed;
108 acceleration *= moveInput * 4;
112 acceleration *= -Math.Sign(rb.velocity.x) * 16;
119 if (! HasReachedTV(acceleration))
121 int oldSign = Math.Sign(rb.velocity.x);
122 rb.velocity += new Vector2(acceleration * Time.fixedDeltaTime, 0);
124 if (HasReachedTV(acceleration))
125 rb.velocity = new Vector2(Math.Sign(rb.velocity.x) * speed, rb.velocity.y);
126 if (oldSign == -Math.Sign(rb.velocity.x))
127 rb.velocity = new Vector2(0, rb.velocity.y);
130 if (isGrounded == true && Input.GetButtonDown("Jump"))
133 jumpTimeCounter = jumptime;
134 rb.velocity = new Vector2(rb.velocity.x, jumpForce);
137 if (Input.GetButton("Jump") && isJumping == true)
139 if (jumpTimeCounter > 0)
141 rb.velocity = new Vector2(rb.velocity.x, jumpForce);
142 jumpTimeCounter -= Time.fixedDeltaTime;
143 FindObjectOfType<AudioManager>().Play("sprung");