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 PlayerMovement : MonoBehaviour
- {
- public float speed = 3.0f;
- public float rotSpeed = 150.0f;
- private bool isSprinting;
- public Rigidbody rb;
- private bool canJump;
- private bool isJumping;
- // Update is called once per frame
- void Update()
- {
- var x = Input.GetAxis("Horizontal") * Time.deltaTime * rotSpeed;
- var z = Input.GetAxis("Vertical") * Time.deltaTime * speed;
- transform.Rotate(0, x, 0);
- transform.Translate(0, 0, z);
- //poruszanie sie
- if (Input.GetKeyDown(KeyCode.LeftShift))
- {
- speed = 5.0f;
- isSprinting = true;
- }
- if (Input.GetKeyUp(KeyCode.LeftShift))
- {
- speed = 3.0f;
- isSprinting = false;
- }
- //sprint
- if (Input.GetKeyDown(KeyCode.Space))
- {
- if (canJump == true)
- {
- rb.AddForce(0, 10000 * Time.deltaTime, 0);
- }
- else if(Input.GetKeyDown(KeyCode.Space) && isJumping)
- {
- }
- }
- }
- private void OnCollisionEnter(Collision collision)
- {
- if(collision.gameObject.tag == "ground")
- {
- canJump = true;
- Debug.Log("moge skakac");
- }
- }
- private void OnCollisionExit(Collision collision)
- {
- if (collision.gameObject.tag == "ground")
- {
- canJump = false;
- isJumping = true;
- Debug.Log("nie moge skakac bo skoczylem se wlasnie xD");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement