I’m toying with the Survival Shooter tutorial - still learning, very new.
What I’ve done is create a prefab, attached my Slider “Slider” to it.
In the script I reference:
public Slider powerSlider
I attempt to call the current powerSlider.value
and as you can see behind the // I have also attempted to just call the value into integer form
I now believe that the form of
int damage = (int) (powerSlider.value);
is only for static integers?
Is that my issue? it keeps coming in null
when I read about this, I attempted a few other methods and after failures I tried what is below… All failures. All results in null return.
I have made a prefab for the Slider, linked it in the inspector, the Slider value is changed by +/- by the keyboard and moves on the GUI no problem.
So it’s getting updated and showing value on screen during game play, but not sharing that value to my damage integer.
void OnHit
etc…etc…etc…
if (hit.transform.tag == “Enemy”) {
ImpactParticles.transform.position = hit.point;
ImpactParticles.transform.rotation = rotation;
ImpactParticles.Play();
int damage = (int) Mathf.Round(((float)powerSlider.value / (float) powerSlider.maxValue ) * 100);
//int damage = (int) (powerSlider.value);
2364817–160542–EnergyBlast.cs (5.64 KB)