Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class CharController : MonoBehaviour
  5. {
  6. public Rigidbody2D rb2d;
  7. public float playerSpeed;
  8. public float jumpPower;
  9. public int directionInput;
  10. public bool groundCheck;
  11. public bool facingRight = true;
  12.  
  13.  
  14. void Start()
  15. {
  16. rb2d = GetComponent<Rigidbody2D>();
  17.  
  18. }
  19.  
  20.  
  21. void Update()
  22. {
  23. if ((directionInput < 0) && (facingRight))
  24. {
  25. Flip();
  26. }
  27.  
  28. if ((directionInput > 0) && (!facingRight))
  29. {
  30. Flip();
  31. }
  32. groundCheck = true;
  33. }
  34.  
  35. void FixedUpdate()
  36. {
  37. rb2d.velocity = new Vector2(playerSpeed * directionInput, rb2d.velocity.y);
  38. }
  39.  
  40. public void Move(int InputAxis)
  41. {
  42.  
  43. directionInput = InputAxis;
  44.  
  45. }
  46.  
  47. public void Jump(bool isJump)
  48. {
  49. isJump = groundCheck;
  50.  
  51. if (groundCheck)
  52. {
  53. rb2d.velocity = new Vector2(rb2d.velocity.x, jumpPower);
  54. }
  55.  
  56. }
  57.  
  58. void Flip()
  59. {
  60. facingRight = !facingRight;
  61. Vector3 theScale = transform.localScale;
  62. theScale.x *= -1;
  63. transform.localScale = theScale;
  64. }
  65.  
  66.  
  67. }