Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- public class UnityMover : MonoBehaviour
- {
- public float Speed = 6f;
- public float JumpForce = 8f;
- public float Gravity = 9.83f;
- CharacterController controller;
- void Awake()
- {
- controller = GetComponent<CharacterController>();
- }
- void Update()
- {
- Vector3 moveDirection = new Vector3(Input.GetAxis("Horizontal"), 0f, Input.GetAxis("Vertical"));
- moveDirection = transform.TransformDirection(moveDirection);
- moveDirection *= Speed;
- if(Input.GetButton("Jump") && controller.isGrounded)
- {
- moveDirection.y = JumpForce;
- }
- moveDirection.y -= Gravity * Time.deltaTime;
- controller.Move(moveDirection * Time.deltaTime);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement