Advertisement
Guest User

Untitled

a guest
Apr 24th, 2017
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.37 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class PlayerC : MonoBehaviour {
  6.  
  7.     private float movementSpeed = 8.0f;
  8.     private float walkSpeed = 4.5f;
  9.     private float gravity = 5.0f;
  10.     private float gforce;
  11.     private Vector3 direction;
  12.     CharacterController player;
  13.     Animator anim;
  14.  
  15.  
  16.     // Use this for initialization
  17.     void Start () {
  18.         player = GetComponent<CharacterController>();
  19.         anim = GetComponent<Animator>();
  20.     }
  21.    
  22.     // Update is called once per frame
  23.     void Update () {
  24.         gforce = Time.deltaTime * gravity;
  25.         player.Move(Vector3.down * gforce);
  26.         movementSpeed = 8.0f;
  27.         if (player.isGrounded)
  28.         {
  29.             gforce = 0;
  30.             Vector3 agg = new Vector3();
  31.             if (Input.GetButton("W"))
  32.             {
  33.                 agg += transform.forward;
  34.             }
  35.             else
  36.             {
  37.                 if (Input.GetButton("S")) {
  38.                     agg -= transform.forward;
  39.                     movementSpeed = walkSpeed;
  40.                 }
  41.             }
  42.             if (Input.GetButton("A")) agg -= transform.right;
  43.             if (Input.GetButton("D")) agg += transform.right;
  44.             agg = agg.normalized;
  45.             transform.position += agg * Time.smoothDeltaTime * movementSpeed;
  46.                
  47.         }
  48.        
  49.     }
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement