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 float moveInput;
16 public float coyoteTime;
17 private float coyoteTimeCounter;
19 public float jumpBufferLength;
20 private float jumpBufferCounter;
23 public bool isGrounded;
24 public Transform groundcheck;
25 public float checkRadius;
26 public LayerMask whatIsGround;
30 public bool isFacingLeft;
32 private bool isShooting;
38 Transform bulletSpawnPos;
41 private float shootDelay = 0.5f;
45 //Hier wird der Rigidbody initialisiert
46 rb = GetComponent<Rigidbody2D>();
48 powerUps = GetComponent<PowerUps>();
56 coyoteTimeCounter = coyoteTime;
59 coyoteTimeCounter -= Time.deltaTime;
62 //manage jump buffering
63 if (Input.GetButtonDown("Jump"))
65 jumpBufferCounter = jumpBufferLength;
68 jumpBufferCounter -= Time.deltaTime;
72 if (jumpBufferCounter >= 0 && coyoteTimeCounter > 0)
75 rb.velocity = new Vector2(rb.velocity.x, jumpForce);
76 jumpBufferCounter = 0;
77 coyoteTimeCounter = 0;
80 //jumping with different height
81 if (Input.GetButtonUp("Jump") && rb.velocity.y > 0)
83 rb.velocity = new Vector2(rb.velocity.x, jumpForce * 0.5f);
86 if (rb.velocity.x < 0)
88 transform.localScale = new Vector3(-1, 1, 1);
91 else if (rb.velocity.x > 0)
93 transform.localScale = new Vector3(1, 1, 1);
97 if (powerUps.mouseIsGardener == true)
99 if (Input.GetButtonDown("Fire1") && ! isShooting)
103 GameObject b = Instantiate(bullet);
104 b.GetComponent<Scissors>().StartShoot(isFacingLeft, rb.velocity);
105 b.transform.position = bulletSpawnPos.transform.position;
107 Invoke("ResetShoot", shootDelay);
111 moveInput = Input.GetAxisRaw("Horizontal");
114 bool HasReachedTV(float acceleration)
116 if (acceleration < 0)
118 if (rb.velocity.x <= -speed)
121 else if (acceleration > 0)
123 if (rb.velocity.x >= speed)
132 //Hier wird ein Kreis unter der Maus erzeugt, der prueft, ob die Maus den Boden beruehrt
133 isGrounded = Physics2D.OverlapCircle(groundcheck.position, checkRadius, whatIsGround);
135 //Wenn a und d oder Pfeiltaste links und rechts gedrueckt werden, ist der Wert von moveInput -1 oder 1;
137 float acceleration = speed;
141 acceleration *= moveInput * 3;
145 acceleration *= -Math.Sign(rb.velocity.x) * 16;
152 if (! HasReachedTV(acceleration))
154 int oldSign = Math.Sign(rb.velocity.x);
155 rb.velocity += new Vector2(acceleration * Time.fixedDeltaTime, 0);
157 if (HasReachedTV(acceleration))
158 rb.velocity = new Vector2(Math.Sign(rb.velocity.x) * speed, rb.velocity.y);
159 if (oldSign == -Math.Sign(rb.velocity.x))
160 rb.velocity = new Vector2(0, rb.velocity.y);