Advertisement
Guest User

Untitled

a guest
Mar 12th, 2017
556
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.63 KB | None | 0 0
  1.  
  2. using UnityEngine;
  3. using System.Collections;
  4.  
  5. public class PlayerController : MonoBehaviour
  6. {
  7.  
  8. public float moveSpeed;
  9.  
  10. private Animator anim;
  11.  
  12. private bool playerMoving;
  13. private Vector2 lastMove;
  14.  
  15.  
  16. // Use this for initialization
  17. void Start()
  18. {
  19.  
  20. anim = GetComponent<Animator>();
  21. }
  22.  
  23. // Update is called once per frame
  24. void Update()
  25. {
  26.  
  27. playerMoving = false;
  28.  
  29. if (Input.GetAxisRaw("Horizontal") > 0.5f || Input.GetAxisRaw("Horizontal") < -0.5f)
  30. {
  31. transform.Translate(new Vector3(Input.GetAxisRaw("Horizontal") * moveSpeed * Time.deltaTime, 0f, 0f));
  32. playerMoving = true;
  33. lastMove = new Vector2(Input.GetAxisRaw("Horizontal"), 0f);
  34. }
  35. if (Input.GetAxisRaw("Vertical") > 0.5f || Input.GetAxisRaw("Vertical") < -0.5f)
  36. {
  37. transform.Translate(new Vector3(0f, Input.GetAxisRaw("Vertical") * moveSpeed * Time.deltaTime, 0f));
  38. playerMoving = true;
  39. lastMove = new Vector2(0f, Input.GetAxisRaw("Vertical"));
  40. }
  41.  
  42. //2d beat em up
  43. if (transform.position.y > Object.transform.position.y) {
  44. {
  45. transform.position.Set(transform.position.x, transform.position.y, -1);
  46.  
  47. }
  48.  
  49. anim.SetFloat("MoveX", Input.GetAxisRaw("Horizontal"));
  50. anim.SetFloat("MoveY", Input.GetAxisRaw("Vertical"));
  51. anim.SetBool("PlayerMoving", playerMoving);
  52. anim.SetFloat("LastMoveX", lastMove.x);
  53. anim.SetFloat("LastMoveY", lastMove.y);
  54.  
  55. }
  56. }
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement