Guest User

Untitled

a guest
Dec 17th, 2017
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.59 KB | None | 0 0
  1. public class CharacterControls : MonoBehaviour {
  2.  
  3. public float maxSpeed = 10f;
  4. bool facingRight = true;
  5. Animator anim;
  6.  
  7. ///////Jump animation variables
  8. bool grounded = false;
  9. public Transform groundCheck;
  10. float groundRadius = 0.2f;
  11.  
  12. public LayerMask whatIsGround;
  13.  
  14. public float jumpForce = 700;
  15.  
  16.  
  17. // Use this for initialization
  18. void Start () {
  19.  
  20. anim = GetComponent<Animator> ();
  21.  
  22. }
  23.  
  24.  
  25. // Update is called once per frame
  26. void FixedUpdate () {
  27.  
  28. //jumping check
  29. grounded = Physics2D.OverlapCircle (groundCheck.position, groundRadius, whatIsGround);
  30. anim.SetBool ("Ground", grounded);
  31.  
  32. anim.SetFloat ("vSpeed", GetComponent<Rigidbody2D>().velocity.y);
  33.  
  34. float move = Input.GetAxis ("Horizontal");
  35.  
  36. anim.SetFloat ("Speed", Mathf.Abs (move));
  37.  
  38. //Diving maxSpeed by 2 to slow down the walker
  39. GetComponent<Rigidbody2D>().velocity = new Vector2 (move * maxSpeed/2, GetComponent<Rigidbody2D>().velocity.y);
  40. if (move > 0 && !facingRight) {
  41. Flip ();
  42. }
  43. else if (move < 0 && facingRight) {
  44. Flip ();
  45. }
  46. }
  47.  
  48.  
  49. void Update() {
  50.  
  51. if (grounded && Input.GetKeyDown (KeyCode.Space)) {
  52. anim.SetBool("Ground", false);
  53. GetComponent<Rigidbody2D>().AddForce(new Vector2(0,jumpForce));
  54. }
  55. }
  56.  
  57.  
  58. public void jump_button(){
  59. anim.SetBool("Ground", false);
  60. GetComponent<Rigidbody2D>().AddForce(new Vector2(0,jumpForce));
  61.  
  62. }
  63.  
  64.  
  65. void Flip() {
  66. Debug.Log ("You are inside flip function");
  67. facingRight = !facingRight;
  68. Vector3 theScale = transform.localScale;
  69. theScale.x *= -1;
  70. Debug.Log (theScale.x);
  71. transform.localScale = theScale;
  72. }
  73. }
Add Comment
Please, Sign In to add comment