Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- public class PlayerController : MonoBehaviour
- {
- public CharacterController cc;
- public float Speed;
- public float JumpHeight;
- Vector3 move;
- private void Start()
- {
- cc = GetComponent<CharacterController>();
- }
- private void Update()
- {
- float y = move.y;
- move = new Vector3(Input.GetAxisRaw("Horizontal"), 0, 0) * Speed;
- move.y = y;
- if (cc.isGrounded)
- {
- move.y = 0;
- if (Input.GetButtonDown("Jump"))
- {
- move.y = JumpHeight;
- }
- }
- move.y = move.y + (Physics.gravity.y * 1f * Time.deltaTime);
- cc.Move(move * Time.deltaTime);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement