Hey guys,
trying to make a power bar that increases fill amount as I hold down a button. I can get the bar to when i set it to one but it does not want to update from the variable on the other script. Here is a sample of what I am doing.
This is my scripts that holds the image and controls the fillamount that is set by the amount of power applies.
using UnityEngine.UI;
using UnityEngine;
public class PowerBar : MonoBehaviour
{
public Image powerbar;
public BallLaunch ballLaunch;
void Update()
{
powerbarcheck();
}
void powerbarcheck()
{
powerbar.fillAmount = ballLaunch.power/1500f;
}
}
This scripts is responsible for launching the ball and increasing and decreasing power depending on how much is gained or lost.
public float power = 0f;
private float increase = 500f;
public bool maxPower = false;
public bool minPower = true;
void Update()
{
Launch();
PowerCheck();
}
void Launch()
{
if (Input.GetButton("Fire1") && ballInPlay == false && minPower == true)
{
power += increase * Time.deltaTime;
}
if (Input.GetButton("Fire1") && ballInPlay == false && maxPower == true)
{
power -= increase * Time.deltaTime;
void PowerCheck()
{
if (power <= 0)
{
maxPower = false;
minPower = true;
}
if (power >= 1500f)
{
maxPower = true;
minPower = false;
}
}
I think that everything relevant…Thanks in advance!