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 public 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>();
43 FindObjectOfType<AudioManager>().Play("flowers");
46 // Update is called once per frame
49 if (isGrounded == true && Input.GetButtonDown("Jump"))
52 jumpTimeCounter = jumptime;
53 rb.velocity = new Vector2(rb.velocity.x, jumpForce);
56 if (Input.GetButton("Jump") && isJumping == true)
58 if (jumpTimeCounter > 0)
60 rb.velocity = new Vector2(rb.velocity.x, jumpForce);
61 jumpTimeCounter -= Time.deltaTime;
62 FindObjectOfType<AudioManager>().Play("sprung");
66 if (Input.GetButtonUp("Jump"))
71 if (rb.velocity.x < 0)
73 transform.localScale = new Vector3(-1, 1, 1);
76 else if (rb.velocity.x > 0)
78 transform.localScale = new Vector3(1, 1, 1);
82 if (powerUps.mouseIsGardener == true)
84 if (Input.GetButtonDown("Fire1") && ! isShooting)
88 GameObject b = Instantiate(bullet);
89 b.GetComponent<Scissors>().StartShoot(isFacingLeft, rb.velocity);
90 b.transform.position = bulletSpawnPos.transform.position;
92 Invoke("ResetShoot", shootDelay);
96 moveInput = Input.GetAxisRaw("Horizontal");
99 bool HasReachedTV(float acceleration)
101 if (acceleration < 0)
103 if (rb.velocity.x <= -speed)
106 else if (acceleration > 0)
108 if (rb.velocity.x >= speed)
117 //Hier wird ein Kreis unter der Maus erzeugt, der prueft, ob die Maus den Boden beruehrt
118 isGrounded = Physics2D.OverlapCircle(groundcheck.position, checkRadius, whatIsGround);
120 //Wenn a und d oder Pfeiltaste links und rechts gedrueckt werden, ist der Wert von moveInput -1 oder 1;
122 float acceleration = speed;
126 acceleration *= moveInput * 4;
130 acceleration *= -Math.Sign(rb.velocity.x) * 16;
137 if (! HasReachedTV(acceleration))
139 int oldSign = Math.Sign(rb.velocity.x);
140 rb.velocity += new Vector2(acceleration * Time.fixedDeltaTime, 0);
142 if (HasReachedTV(acceleration))
143 rb.velocity = new Vector2(Math.Sign(rb.velocity.x) * speed, rb.velocity.y);
144 if (oldSign == -Math.Sign(rb.velocity.x))
145 rb.velocity = new Vector2(0, rb.velocity.y);