Advertisement
Guest User

Untitled

a guest
May 17th, 2019
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.29 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class chodzenie : MonoBehaviour {
  6.     float speed = 4f;
  7.     float rotspeed = 80f;
  8.     float rot = 0f;
  9.     float gravity = 4f;
  10.     Vector3 moveDir = Vector3.zero;
  11.     public float jumpSpeed = 4f;
  12.     CharacterController controller;
  13.    
  14.     // Use this for initialization
  15.     void Start () {
  16.         controller = GetComponent<CharacterController>();
  17.     }
  18.    
  19.     // Update is called once per frame
  20.     void Update () {
  21.  
  22.         if (controller.isGrounded) {
  23.             if (Input.GetKey(KeyCode.W)) {
  24.                
  25.                     moveDir = new Vector3(0, 0, 1);
  26.                     moveDir *= speed;
  27.                     moveDir = transform.TransformDirection(moveDir);
  28.                
  29.  
  30.             }
  31.             if (Input.GetKeyUp(KeyCode.W))
  32.             {
  33.                 moveDir = new Vector3(0, 0, 0);
  34.                
  35.             }
  36.  
  37.             if (Input.GetKeyUp(KeyCode.Space)) {
  38.  
  39.                 moveDir.y = jumpSpeed;
  40.             }
  41.  
  42.         }
  43.  
  44.        
  45.  
  46.         rot += Input.GetAxis("Mouse X") * rotspeed * Time.deltaTime;
  47.         transform.eulerAngles = new Vector3(0, rot, 0);
  48.         moveDir.y -= gravity * Time.deltaTime;
  49.         controller.Move(moveDir*Time.deltaTime);
  50.  
  51.     }
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement