Advertisement
Guest User

Untitled

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