using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; public class ForceBarController : MonoBehaviour { private Image bar; [SerializeField] private Image backgroundBar; [SerializeField] private Rigidbody2D playerRb; [SerializeField] private Animator playerAnim; private bool isDumping; private bool shotAttemped; private bool canShoot; private float force; private void Start() { bar = GetComponent<Image>(); backgroundBar.fillAmount = 0; canShoot = true; } private void FixedUpdate() { if (playerRb.velocity == Vector2.zero) { if (shotAttemped && Input.GetAxis("Shot") == 0) { force = bar.fillAmount; shotAttemped = false; isDumping = false; FindObjectOfType<GameManager>().shoot(force); bar.fillAmount = 0; backgroundBar.fillAmount = 0; playerAnim.SetBool("Shooting", false); } if (Input.GetAxis("Shot") != 0) { playerAnim.SetBool("Shooting", true); backgroundBar.fillAmount = 1; if (bar.fillAmount < 1 && !isDumping) { bar.fillAmount += Time.deltaTime; } else if (bar.fillAmount == 1) { //perfect isDumping = true; } if (isDumping) { bar.fillAmount -= Time.deltaTime; } shotAttemped = true; } } } private void updateState() { canShoot = canShoot == true ? false : true; } }