Guest User

Untitled

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