Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- public class movement : MonoBehaviour {
- public Animation anim;
- void Update ()
- {
- if (Input.GetKeyDown(KeyCode.W) || Input.GetKeyDown(KeyCode.S) || Input.GetKeyDown(KeyCode.A) || Input.GetKeyDown(KeyCode.D))
- {
- Walk(true);
- }
- else if (!Input.GetKey(KeyCode.W) && !Input.GetKey(KeyCode.S) && !Input.GetKey(KeyCode.A) && !Input.GetKey(KeyCode.D))
- {
- Walk(false);
- }
- if (Input.GetKeyDown(KeyCode.LeftShift) && Input.GetKey(KeyCode.W) || Input.GetKeyDown(KeyCode.W) && Input.GetKey(KeyCode.LeftShift))
- {
- Run(true);
- }
- else if (Input.GetKeyUp(KeyCode.LeftShift) && Input.GetKey(KeyCode.W))
- {
- Walk(true);
- }
- else if (Input.GetKeyUp(KeyCode.LeftShift) && Input.GetKeyUp(KeyCode.W))
- {
- Run (false);
- Walk(false);
- }
- else if (Input.GetKeyDown(KeyCode.LeftShift) && Input.GetKey(KeyCode.S) || Input.GetKeyDown(KeyCode.S) && Input.GetKey(KeyCode.LeftShift))
- {
- Run(true);
- }
- else if (Input.GetKeyUp(KeyCode.LeftShift) && Input.GetKey(KeyCode.S))
- {
- Walk(true);
- }
- else if (Input.GetKeyUp(KeyCode.LeftShift) && Input.GetKeyUp(KeyCode.S))
- {
- Run(false);
- Walk(false);
- }
- }
- public void Run(bool running)
- {
- if (running)
- {
- anim.Play ("run_forward");
- }
- else
- {
- anim.CrossFade("idle");
- }
- }
- public void Walk(bool walk)
- {
- if (walk)
- {
- anim.Play ("walking");
- }
- else
- {
- anim.CrossFade ("idle");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement