- Home /
The question is answered, right answer was accepted
is there a way to minimize amount of public items in inspector?
I've ran into a situation in my UI that the inspector is holding way too many public variables. And since i'm new to unity, i'm not sure if this is common practice, or should i use alternative ways, like "GetComponents" or "Resource.Load"
here are some examples of my situation:
as you can see, my main issue is with the sprites. since i hide/show/switch them from code, i need a reference for them.
so all i'm asking, is if this is a common practice, or is there a better way?
Answer by saud_ahmed020 · Apr 12, 2015 at 12:28 PM
http://answers.unity3d.com/questions/907918/is-there-any-way-to-write-one-hideininspector-for.html
use it for hiding public gameobjects in inspector
[HideInInspector]
Î converted the post to an answer since it accurately answers the question :)
Okay, this helps with public variables that i don't want to change from inspector, so thanks :)
what about the sprites that needs reference, should i leave it the way it is?
You can use Unitys resource.load for loading sprites ins$$anonymous$$d of using inspector fields.
You can also do GameObject.Find on start to find objects but it's advised to never use GameObject.Find outside of start as its expensive.
Do i have to put my sprites in folder named Resources in order for this to work?
@Notter You can use following code to load from resources.
Sprite sprite = Resources.Load<Sprite>("spriteName") as Sprite;
spriteRenderer.sprite = sprite;
Follow this Question
Related Questions
How to make public variable read-only during run-time? 3 Answers
c# public variables not appearing in inspector 0 Answers
How to enter minimum and maximum values for random.Range in the inspector? 1 Answer
public script variable in inspector 2 Answers
Unity scriptable object inspector, field overlap eachother 0 Answers