Advertisement
Guest User

Untitled

a guest
Feb 23rd, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.49 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class move : MonoBehaviour {
  6.     Animator anim;
  7.     public float playerSpeed = 3f;
  8.     private bool playerMoving;
  9.     private Vector3 lastMove;
  10.  
  11.     // Use this for initialization
  12.     void Start () {
  13.         anim = GetComponent<Animator>();
  14.     }
  15.    
  16.     // Update is called once per frame
  17.     void Update () {
  18.         playerMoving = false;
  19.     //    float moveHori = Input.GetAxis("Horizontal");
  20.     //    float moveVert = Input.GetAxis("Vertical");
  21.    
  22.  
  23.         if (Input.GetAxisRaw("Horizontal") > 0.5f || Input.GetAxisRaw("Horizontal") < -0.5f)
  24.         {
  25.             transform.Translate(new Vector3(Input.GetAxisRaw("Horizontal") * playerSpeed * Time.deltaTime, 0f, 0f));
  26.             playerMoving = true;
  27.             lastMove = new Vector3(Input.GetAxis("Horizontal"),0f,0f);
  28.         }
  29.  
  30.         if (Input.GetAxisRaw("Vertical") > 0.5f || Input.GetAxisRaw("Vertical") < -0.5f)
  31.         {
  32.             transform.Translate(new Vector3(0f,0f, Input.GetAxisRaw("Vertical") * playerSpeed * Time.deltaTime));
  33.             playerMoving = true;
  34.             lastMove = new Vector3(0f,0f,Input.GetAxis("Vertical"));
  35.         }
  36.  
  37.  
  38.         anim.SetFloat("HoriSpeed", Input.GetAxis("Horizontal"));
  39.         anim.SetFloat("VertSpeed", Input.GetAxis("Vertical"));
  40.         anim.SetBool("PlayerMoving", playerMoving);
  41.         anim.SetFloat("LastMoveX", lastMove.x);
  42.         anim.SetFloat("LastMoveY", lastMove.z);
  43.     }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement