Im trying to create a button and multiple Sliders that update based each others values. Since every button and set of sliders is highly related I tried to call one method that would update the set, therefore I call one Update method for GenerateItem, rather than calling Update on each Object and making them reference each other.
Why am I getting the error above, and what is the "Unity" way to solve this? My program will likely have a lot of these sliders and Buttons so I would rather not code them all by hand.
GenerateItem must be instantiated using the ScriptableObject.CreateInstance method instead of new GenerateItem
void Start () {
Button a = ((GameObject)Instantiate(prefabButton)).GetComponent<Button>();
Slider b = ((GameObject)Instantiate(prefabCreationSlider)).GetComponent<Slider>();
Slider c = ((GameObject)Instantiate(prefabCapacitySlider)).GetComponent<Slider>();
Text d = ((GameObject)Instantiate(prefabText)).GetComponent<Text>();
items.Add(new GenerateItem("OxyGen", 0.5f, 50f,a,c,b,d));
}
// Update is called once per frame
void Update () {
items.ForEach(a => a.BtnUpdate());
}
I tried:
GenerateItem o= ScriptableObject.CreateInstance(GenerateItem);
but couldn't figure out how to set the properties of the object.