- Home /
minmaxslider problem (Javascript)
Hi,
I using a custom editor script, and want to modify two variables at the same time using a minmaxslider. Here's the code for the line I'm using:
EditorGUILayout.MinMaxSlider(target.elementArray[i].randomYFOstart, target.elementArray[i].randomYFOend, 0.0, 1.0);
Both of the first two things are variables from an array of objects, but I get the following error code:
No appropriate version of 'UnityEditor.EditorGUILayout.MinMaxSlider' for the argument list '(System.Object, System.Object, float, float)' was found.
I don't understand why Unity thinks those first two things are System.Object when they are defined and set up as float variables in the main script this editor script refers to. I have loads of other variables, set up in the same way, feeding perfectly into the editor script as IntSliders, Sliders, TextFields etc. etc. What am I doing wrong? I read on here (in the only other question relating to minmaxsliders) that in C# you need to add 'ref' to the beginning of the first two items, but that confuses the hell out of Unity. Anyone help me? Thanks!
Are they Objects or GameObjects? You may be missing an explicit cast somewhere. The fact that this stuff is not exactly clear is why I don't use javascript, btw.
Hmmm. $$anonymous$$ay show my igonrance here: elementArray is a builtin array of GameObjects which are a class with a number of variables in. Does that answer the question. $$anonymous$$now I'll probably have to learn C# one day. But only started program$$anonymous$$g about 4 months ago, so one language at a time!
Answer by aldonaletto · Oct 05, 2011 at 03:41 PM
This error usually appears when Unity doesn't know the argument type - specially when you use #pragma strict in your script. You can assign the values to two float variables and use them in the function:
var start: float = target.elementArray[i].randomYFOstart; var end: float = target.elementArray[i].randomYFOend; EditorGUILayout.MinMaxSlider(start, end, 0.0, 1.0);And don't abandon Unityscript so soon! It's easier and much more concise - the ideal language for scripts, in my opinion. C# requires much more writing, and is like a cranky old aunt, complaining all the time about everything: hey, you must write "0.5f", not "0.5", stupid! you must declare "new Vector3(x,y,z)", not just "Vector3(x,y,z)", you incompetent! and so on...
That works for showing the $$anonymous$$maxslider, but unfortunately it isn't editable - I can't drag the ends of the slider to adjust the values. If I edit the two variables it's showing (target.elementArray[i].randomYFOstart and target.elementArray[i].randomYFOend) by another means (ie. with their own slider) then the $$anonymous$$maxslider does update to show the right values. How can I make the $$anonymous$$maxslider be the thing that changes the values it represents? Thanks for your help so far though :)
If randomYFOstart and randomYFOend are both explicitly typed as floats, $$anonymous$$in$$anonymous$$axSlider should work (I mean, if they are declared like "randomYFOstart: float", not like "randomYFOstart = 0.0;")
Anyway, I believe that something like this could work:
var start: float = target.elementArray[i].randomYFOstart; var end: float = target.elementArray[i].randomYFOend; EditorGUILayout.$$anonymous$$in$$anonymous$$axSlider(start, end, 0.0, 1.0); target.elementArray[i].randomYFOstart = start; target.elementArray[i].randomYFOend = end;I don't know how $$anonymous$$in$$anonymous$$axSlider works internally - if each user action takes more than one OnGUI cycle to become effective, this will fail miserably.