Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class PlayerMove : MonoBehaviour
- {
- public float speed;
- public float jumpForce;
- private float moveInput;
- private Rigidbody2D rb;
- private bool facingRight = true;
- private bool isGrounded;
- public Transform groundCheck;
- public float checkRadius;
- public LayerMask whatIsGround;
- private int extraJumps;
- public int extraJumpsValue;
- public int health = 100;
- //Śmierć gracza
- void OnCollisionEnter2D(Collision2D coll)
- {
- //lawa
- if ( coll.gameObject.tag == "Lava" )
- {
- Destroy(gameObject);
- }
- //Przeciwnik zabija po dotyku
- if ( coll.gameObject.tag == "Enemy" )
- {
- Destroy(gameObject);
- }
- }
- //życie
- public void takeDamage(int damage)
- {
- health -= damage;
- if ( health <= 0 )
- {
- Die();
- }
- }
- void Die()
- {
- Destroy(gameObject);
- }
- void Start()
- {
- extraJumps = extraJumpsValue;
- rb = GetComponent<Rigidbody2D>();
- }
- void FixedUpdate()
- {
- //obrót postaci
- isGrounded = Physics2D.OverlapCircle(groundCheck.position, checkRadius, whatIsGround);
- moveInput = Input.GetAxis("Horizontal");
- rb.velocity = new Vector2( moveInput * speed, rb.velocity.y );
- if ( facingRight == false && moveInput > 0 )
- {
- Flip();
- } else if ( facingRight == true && moveInput < 0 )
- {
- Flip();
- }
- }
- void Update()
- {
- //skok
- if(isGrounded == true)
- {
- extraJumps = extraJumpsValue;
- }
- if(Input.GetKeyDown(KeyCode.Space) && extraJumps > 0)
- {
- rb.velocity = Vector2.up * jumpForce;
- extraJumps--;
- } else if ( Input.GetKeyDown(KeyCode.Space) && extraJumps == 0 && isGrounded == true )
- {
- rb.velocity = Vector2.up * jumpForce;
- }
- }
- //obrót postaci
- void Flip()
- {
- facingRight = !facingRight;
- transform.Rotate(0f, 180f, 0f);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement