Advertisement
Guest User

Untitled

a guest
Aug 20th, 2019
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.30 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class PlayerMove : MonoBehaviour
  6. {
  7.  
  8. public float speed;
  9. public float jumpForce;
  10. private float moveInput;
  11.  
  12. private Rigidbody2D rb;
  13.  
  14. private bool facingRight = true;
  15.  
  16. private bool isGrounded;
  17. public Transform groundCheck;
  18. public float checkRadius;
  19. public LayerMask whatIsGround;
  20.  
  21.  
  22.  
  23. private int extraJumps;
  24. public int extraJumpsValue;
  25.  
  26. public int health = 100;
  27.  
  28. //Śmierć gracza
  29.  
  30. void OnCollisionEnter2D(Collision2D coll)
  31. {
  32. //lawa
  33. if ( coll.gameObject.tag == "Lava" )
  34. {
  35. Destroy(gameObject);
  36. }
  37.  
  38. //Przeciwnik zabija po dotyku
  39.  
  40. if ( coll.gameObject.tag == "Enemy" )
  41. {
  42. Destroy(gameObject);
  43. }
  44. }
  45.  
  46. //życie
  47.  
  48. public void takeDamage(int damage)
  49. {
  50.  
  51. health -= damage;
  52.  
  53. if ( health <= 0 )
  54. {
  55. Die();
  56. }
  57.  
  58. }
  59.  
  60. void Die()
  61. {
  62. Destroy(gameObject);
  63. }
  64.  
  65.  
  66.  
  67. void Start()
  68. {
  69. extraJumps = extraJumpsValue;
  70. rb = GetComponent<Rigidbody2D>();
  71.  
  72. }
  73.  
  74.  
  75. void FixedUpdate()
  76. {
  77. //obrót postaci
  78.  
  79. isGrounded = Physics2D.OverlapCircle(groundCheck.position, checkRadius, whatIsGround);
  80.  
  81.  
  82. moveInput = Input.GetAxis("Horizontal");
  83. rb.velocity = new Vector2( moveInput * speed, rb.velocity.y );
  84.  
  85. if ( facingRight == false && moveInput > 0 )
  86. {
  87. Flip();
  88. } else if ( facingRight == true && moveInput < 0 )
  89. {
  90. Flip();
  91. }
  92.  
  93. }
  94. void Update()
  95. {
  96. //skok
  97.  
  98. if(isGrounded == true)
  99. {
  100. extraJumps = extraJumpsValue;
  101. }
  102.  
  103. if(Input.GetKeyDown(KeyCode.Space) && extraJumps > 0)
  104. {
  105.  
  106. rb.velocity = Vector2.up * jumpForce;
  107. extraJumps--;
  108.  
  109. } else if ( Input.GetKeyDown(KeyCode.Space) && extraJumps == 0 && isGrounded == true )
  110. {
  111. rb.velocity = Vector2.up * jumpForce;
  112. }
  113.  
  114. }
  115.  
  116. //obrót postaci
  117. void Flip()
  118. {
  119.  
  120. facingRight = !facingRight;
  121.  
  122. transform.Rotate(0f, 180f, 0f);
  123.  
  124. }
  125.  
  126. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement