Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class Player : MonoBehaviour
- {
- public Player()
- { }
- private bool jumpKeyWasPressed;
- private float horizontalInput;
- private Rigidbody rigidBodyComponent;
- public Transform groundCheckTransform;
- public int superJumpsRemaining;
- // Start is called before the first frame update
- void Start()
- {
- rigidBodyComponent = GetComponent<Rigidbody>();
- }
- // Update is called once per frame
- void Update()
- {
- if (Input.GetKeyDown(KeyCode.Space))
- {
- jumpKeyWasPressed = true;
- }
- horizontalInput = Input.GetAxis("Horizontal");
- }
- //Fixedupdate wird jedes physikupdate abgerufen (100 mal die sekunde)
- private void FixedUpdate()
- {
- GetComponent<Rigidbody>().velocity = new Vector3(horizontalInput, GetComponent<Rigidbody>().velocity.y, 0);
- if (Physics.OverlapSphere(groundCheckTransform.position, 0.1f).Length == 1)
- {
- return;
- }
- if (jumpKeyWasPressed == true)
- {
- float jumpPower = 5f;
- if(superJumpsRemaining > 0) {
- jumpPower *= 1.5f;
- superJumpsRemaining--;
- }
- Debug.Log("Space wurde gedrückt");
- GetComponent<Rigidbody>().AddForce(Vector3.up * jumpPower, ForceMode.VelocityChange);
- jumpKeyWasPressed = false;
- }
- }
- private void OnTriggerEnter(Collider other)
- {
- if (other.gameObject.layer == 9)
- {
- Destroy(other.gameObject);
- superJumpsRemaining++;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement