Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class move : MonoBehaviour {
- Animator anim;
- public float playerSpeed = 3f;
- private bool playerMoving;
- private Vector3 lastMove;
- // Use this for initialization
- void Start () {
- anim = GetComponent<Animator>();
- }
- // Update is called once per frame
- void Update () {
- playerMoving = false;
- // float moveHori = Input.GetAxis("Horizontal");
- // float moveVert = Input.GetAxis("Vertical");
- if (Input.GetAxisRaw("Horizontal") > 0.5f || Input.GetAxisRaw("Horizontal") < -0.5f)
- {
- transform.Translate(new Vector3(Input.GetAxisRaw("Horizontal") * playerSpeed * Time.deltaTime, 0f, 0f));
- playerMoving = true;
- lastMove = new Vector3(Input.GetAxis("Horizontal"),0f,0f);
- }
- if (Input.GetAxisRaw("Vertical") > 0.5f || Input.GetAxisRaw("Vertical") < -0.5f)
- {
- transform.Translate(new Vector3(0f,0f, Input.GetAxisRaw("Vertical") * playerSpeed * Time.deltaTime));
- playerMoving = true;
- lastMove = new Vector3(0f,0f,Input.GetAxis("Vertical"));
- }
- anim.SetFloat("HoriSpeed", Input.GetAxis("Horizontal"));
- anim.SetFloat("VertSpeed", Input.GetAxis("Vertical"));
- anim.SetBool("PlayerMoving", playerMoving);
- anim.SetFloat("LastMoveX", lastMove.x);
- anim.SetFloat("LastMoveY", lastMove.z);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement