Advertisement
Guest User

Untitled

a guest
Sep 5th, 2015
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.47 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public enum State
  5. {
  6. Normal,
  7. Damaged,
  8. Atack,
  9. Jump,
  10. speaking
  11. }
  12.  
  13. public class controller2D : MonoBehaviour {
  14.  
  15. public float speed=1f;
  16. public float jumpPower=5f;
  17. Rigidbody2D m_rigidbody2D;
  18. public LayerMask groundLayer;
  19. public float up=1f;
  20. public float down=0.1f;
  21. public Vector2 backwardForce = new Vector2(-4.5f, 5.4f);
  22. public GameObject weapon;
  23. public bool canMove=false;
  24. Animator objanimator;
  25. public State playerstate = State.Normal;
  26. bool grounded;
  27.  
  28.  
  29. void Start () {
  30. m_rigidbody2D = GetComponent<Rigidbody2D> ();
  31. objanimator=GetComponent<Animator>();
  32. }
  33.  
  34. void FixedUpdate()
  35. {
  36. grounded = Physics2D.Linecast(
  37. transform.position + transform.up * up,
  38. transform.position - transform.up * down,
  39. groundLayer
  40. );
  41. }
  42.  
  43.  
  44. void Update () {
  45.  
  46. if(canMove){
  47. if (playerstate != State.Damaged)
  48. {
  49. float x = Input.GetAxis("Horizontal");
  50. bool jump = Input.GetKeyDown(KeyCode.Space);
  51. Move(x, jump);
  52. }
  53. }
  54. }
  55.  
  56. void Move(float move, bool jump)
  57. {
  58. if (Mathf.Abs(move) > 0)
  59. {
  60. Quaternion rot = transform.rotation;
  61. transform.rotation = Quaternion.Euler(rot.x, Mathf.Sign(move) == 1 ? 90 : 270, rot.z);
  62. }else{
  63.  
  64. if(Input.GetKeyDown(KeyCode.E)){
  65. objanimator.Play("Atack");
  66. }
  67. }
  68.  
  69. m_rigidbody2D.velocity = new Vector2(move * speed, m_rigidbody2D.velocity.y);
  70. objanimator.SetFloat("run", Mathf.Abs(move));
  71. if (jump&&grounded)
  72. {
  73. m_rigidbody2D.AddForce(Vector2.up * jumpPower);
  74. }
  75. }
  76.  
  77.  
  78.  
  79. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement