Newer
Older
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);
playerAnim.SetBool("Shooting", false);
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;
}
}