Wanting to convert a Slider value into my damage integer on my bullet.

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)

var damage = Mathf.RoundToInt((powerSlider.value / powerSlider.maxValue) * 100);

I think this should work.
Btw, inside a method you can declare your variables with the “var” keyword, the compiler will know what type it is (float, int, class, struct, etc). You usually only “strongly type” a variable inside a method if the type is not obvious.