Advertisement
Michael_smith

Untitled

Mar 31st, 2020
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.88 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class MyMovement : MonoBehaviour
  5. {
  6.  
  7.  
  8.     void Start()
  9.     {
  10.  
  11.     }
  12.  
  13.  
  14.     public float speed = 6.0F;
  15.     public float jumpSpeed = 8.0F;
  16.     public float gravity = 20.0F;
  17.  
  18.     private Vector3 moveDirection = Vector3.zero;
  19.     void Update()
  20.     {
  21.         CharacterController controller = GetComponent<CharacterController>();
  22.         if (controller.isGrounded)
  23.         {
  24.             moveDirection = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
  25.             moveDirection = transform.TransformDirection(moveDirection);
  26.             moveDirection *= speed;
  27.             if (Input.GetButton("Jump"))
  28.             {
  29.                 moveDirection.y = jumpSpeed;
  30.             }
  31.         }
  32.         moveDirection.y -= gravity * Time.deltaTime;
  33.         controller.Move(moveDirection * Time.deltaTime);
  34.     }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement