using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class MobileCont : MonoBehaviour
{
public float horizontalSpeed;
float speedX;
Rigidbody2D rb;
bool isGrounded;
public Transform groundCheck;
public float jumpForce;
public float checkRadius;
public LayerMask whatIsGround;
private int extraJumps;
public int extraJumpsValue;
void Start()
{
extraJumps = extraJumpsValue;
rb = GetComponent<Rigidbody2D>();
}
void FixedUpdate()
{
isGrounded = Physics2D.OverlapCircle(groundCheck.position, checkRadius, whatIsGround);
if(Input.GetKeyDown(KeyCode.Escape))
{
Application.Quit();
}
if (Input.GetKey(KeyCode.A))
{
speedX = -horizontalSpeed;
}
else if (Input.GetKey(KeyCode.D))
{
speedX = horizontalSpeed;
}
}
void OnTriggerEnter2D(Collider2D other)
{
if (other.tag == "KillPL")
{
SceneManager.LoadScene(0);
}
}
void Update()
{
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;
}
}
}
rb.velocity = new Vector2(horizontalSpeed,rb.velocity.y);
void OnCollisionEnter2D(Collision2D coll)
{
if(coll.gameObject.tag == "Ground")
{
isGrounded = true;
}
}