Hope you doing well
I just started game dev, in fact, this is my first game.
Yesterday before making my pc sleep my player scripts were working correctly and the character could jump every time I pressed space.
Today I switched on my pc and looked for a way to add stamina to my guy when he drinks coffee, and it works but then I realized that I could only jump once after the game started.
I tried deleting the coffee loot but the problem persists.
I would be greatly appreciated If someone can help, Thank you.
Here is the code
using System.Collections;
using System.Collections.Generic;
using UnityEngine.UI;
using UnityEngine.SceneManagement;
using UnityEngine;
public class Movement : MonoBehaviour
{
Rigidbody2D rb;
float speed = 0.5f;
public float jumpforce = 2.0f;
public Vector3 jump;
public bool isGrounded;
float stamina = 100f;
float maxStamina = 100f;
private Animator myAnimator;
public Slider slider;
// Start is called before the first frame update
void Start()
{
jump = new Vector3(0f, 2.0f, 0f);
rb = GetComponent<Rigidbody2D>();
myAnimator = GetComponent<Animator>();
}
// Update is called once per frame
void Update()
{
rb.transform.Translate(5f *speed * Time.deltaTime, 0f, 0f);
Jump();
slider.value = stamina;
if (stamina <=maxStamina && speed <= 0.5f)
{
stamina -= 10f * Time.deltaTime;
}
if (stamina <= 0)
{
SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex);
}
if (speed < 0.5f)
{
SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex);
}
//myAnimator.SetBool("isjumping",false);
}
void Jump()
{
if (Input.GetKeyDown(KeyCode.Space)&& isGrounded)
{
rb.AddForce(jump*jumpforce,ForceMode2D.Impulse);
isGrounded = false;
myAnimator.SetBool("isJumping", true);
}
myAnimator.SetBool("isJumping", false);
}
private void OnCollisionEnter2D(Collision2D collision2D)
{
if (collision2D.gameObject.tag == "Coffe")
{
stamina = stamina + 10f;
}
}
}