Advertisement
Guest User

Untitled

a guest
Oct 16th, 2016
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.57 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class movement : MonoBehaviour {
  5.    
  6.     public Animation anim;
  7.  
  8.     void Update ()
  9.     {
  10.         if (Input.GetKeyDown(KeyCode.W) || Input.GetKeyDown(KeyCode.S) || Input.GetKeyDown(KeyCode.A) || Input.GetKeyDown(KeyCode.D))
  11.         {
  12.             Walk(true);
  13.         }
  14.         else if (!Input.GetKey(KeyCode.W) && !Input.GetKey(KeyCode.S) && !Input.GetKey(KeyCode.A) && !Input.GetKey(KeyCode.D))
  15.         {
  16.             Walk(false);
  17.         }
  18.  
  19.         if (Input.GetKeyDown(KeyCode.LeftShift) && Input.GetKey(KeyCode.W) || Input.GetKeyDown(KeyCode.W) && Input.GetKey(KeyCode.LeftShift))
  20.         {
  21.             Run(true);
  22.         }
  23.         else if (Input.GetKeyUp(KeyCode.LeftShift) && Input.GetKey(KeyCode.W))
  24.         {
  25.             Walk(true);
  26.         }
  27.         else if (Input.GetKeyUp(KeyCode.LeftShift) && Input.GetKeyUp(KeyCode.W))
  28.         {
  29.             Run (false);
  30.             Walk(false);
  31.         }
  32.         else if (Input.GetKeyDown(KeyCode.LeftShift) && Input.GetKey(KeyCode.S) || Input.GetKeyDown(KeyCode.S) && Input.GetKey(KeyCode.LeftShift))
  33.         {
  34.             Run(true);
  35.         }
  36.         else if (Input.GetKeyUp(KeyCode.LeftShift) && Input.GetKey(KeyCode.S))
  37.         {
  38.             Walk(true);
  39.         }
  40.         else if (Input.GetKeyUp(KeyCode.LeftShift) && Input.GetKeyUp(KeyCode.S))
  41.         {
  42.             Run(false);
  43.             Walk(false);
  44.         }
  45.     }
  46.  
  47.     public void Run(bool running)
  48.     {
  49.         if (running)
  50.         {
  51.             anim.Play ("run_forward");
  52.         }
  53.         else
  54.         {
  55.             anim.CrossFade("idle");
  56.         }
  57.     }
  58.  
  59.     public void Walk(bool walk)
  60.     {
  61.         if (walk)
  62.         {
  63.             anim.Play ("walking");
  64.         }
  65.         else
  66.         {
  67.             anim.CrossFade ("idle");
  68.         }
  69.     }
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement