Im trying to get the value from my “sliderFill” script to my “ButtonClickTorpedo” script.
But i getting a error on line 10, i think i know what the error means (compare problem?), but not what to replace it with.
Error: code: error CS0019: Operator ==' cannot be applied to operands of type SliderFill’ and `int’[/code]
Here is the code:
public GameObject TorpedoPrefab;
public GameObject TorpPoint;
public Slider PhaserCharged;
public SliderFill curValue;
// Use this for initialization
public void ClickButton(string buttonID)
{
if(curValue == 100)
{
TorpPoint = Instantiate(TorpedoPrefab, new Vector3(0, 0, 0), Quaternion.identity) as GameObject;
//TorpPoint.transform.parent = transform;
TorpPoint.transform.SetParent(transform, false);
}
}
What im trying to do is
1: add a reference to the “curValue” that is in the “SliderFill” script, or else it will tell that “curValue” doesnt exist.
2: read the current “curValue” float info into this script to check if the value is 100f, and if it is 100f it will fire the torpedo.
PhaserCharged contain the “SliderFill” script that makes the sliders go up and down by clicking on a button
Your code will also work if you have a GameObject Somewhere with the SliderFill class on it. And in the editor your dragging that GameObject onto the SliderFill spot in ButtonClickTorpedo script?
If so what happening is curValue is not the curValue from SliderFill, but the actual SliderFill class itself.
So your code would have to say:
if (curValue.curValue == 100)
You can always change the name to something more sensible like:
The SliderFill script are on a slider on my canvas UI, then i have the script at my fist post on the torpedo position.
And if i put both these scripts on the slider, the torpedo shots far away from where it should be