First I would just like to say I’ve looked at various solutions online all over the place and I have tried the solutions that have worked for them, but sadly it has not worked for me.
I have tried many variations of assignment and casting. Oddly enough the above worked for the BarEmptyTex but not the Fill one… in the Resources folder there are two textures on called “FullBar” and one called “EmptyBar”. There are no sub-folders.
also I have tried “Resources.LoadAssetAtPath”
I understand this is a simple problem, but would appreciate the help.
I didn’t know about that function. Plus I do want the progress bar to be on the window. I’m seeing if I can get the one you linked working though. For other things in my project I am going to need to use the Resources in the same way I’m trying to above, so it would be really helpful if I can get help figuring out why it does not work anyway.
Yeah the texture variable is returning null, but why?
What am I doing wrong with the assignment, doing it that way seems to work with so many other people. Why would it work for one of the variables and not the other even though the code was the same except for variable names.
Okay it must just not work when trying to assign it from Start() in the Editor Window, even though I’ve tried shutting unity down and opening it back up incase thats the only time start is called for editor windows.
Using OnGUI() may be best. Start() will only get called if you use ExecuteInEditMode. But in this case Start() gets called every time you start or stop the player.
I thought assigning in OnGUI is kind of inefficient as it is assigning something multiple times every other second rather than it being assigned once at some point and then not doing it again.
I’ve done it in OnGUI for now but if someone has a better alternative I’d be happy to here.
Thanks for the link TonyLi, that might come in handy for something else. I would’ve used that previously but I got something nice working now, so its all good.
I might be missing the point but isn’t that link you sent me just an enhanced graphical representation of the state of a slider?
If its only for Editor window then it cannot be used in game right?
So whats the point of the example, I can only see it being used as a progress/loading bar purpose not to display if you have set a slider to a certain value.
EditorGUI.ProgressBar() is useful if you’re running a lengthy process and want to give feedback on its progress – downloading a file from the web for example.
As for assigning in OnGUI, you should assign once. Something like:
private Texture2D BarEmptyTex = null;
void OnGUI() {
if (BarEmptyTex == null) {
BarEmptyTex = (Texture2D)Resources.Load("EmptyBar", typeof (Texture2D));
}
// draw your GUI here
}