I am able to get the power bar to fill up at a fixed time using the commented out part of the code, but I would like to have the bar go up and down according to the percentage float. Here is the code:
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
public class PowerMeter : MonoBehaviour
{
public Transform PowerMeterBar;
public bool buttonPressed = false;
public int sign = 1;
[SerializeField]
private float percentage;
[SerializeField]
private float currentAmount;
[SerializeField]
private float speed = 30;
void Start ()
{
}
public void ButtonDown()
{
buttonPressed = true;
}
public void ButtonUp()
{
buttonPressed = false;
}
public void Update()
{
if (buttonPressed)
{
percentage += sign;
Debug.Log(percentage);
if (percentage == 100 || percentage == 0)
sign *= -1;
}
//if (currentAmount < 100)
//{
// currentAmount += speed * Time.deltaTime;
//}
//PowerMeterBar.GetComponent<Image>().fillAmount = currentAmount / 100;
PowerMeterBar.GetComponent<Image>().fillAmount = percentage / 100;
}
}