I was wondering if can we change the variable name on inspector without changing it in script.
For example:
using UnityEngine;
using System.Collections;
public class Luces : MonoBehaviour
{
[Header("Luces")]
public Light luzRoja;
}
Instead of saying “Luz Roja” on inspector, I want to say “Roja”.
I have more code, but this is what I see now:
Thanks !
ANSWERED:
Thanks everyone for the answers. I knew that maybe the best options was to create a custom inspector, but for this, is a lot of work and makes no sense… So, it will be Luz Roja
If it could be done, it would have to be through serialization. The thing is that it is not a good idea to have a variable name for a script variable because, say that you want to access that variable through another script. Unity wouldn’t know what to access once it finds a variable named ‘Roja’ because in the script it is called ‘Luz Roja’ so it won’t make the connection.
I recommend changing it in the script if you don’t want headaches.
I would recommend against changing the field names as they show up. The big reason (there are others), is think of anytime you have tried to GetComponent<…>() and couldn’t find fields that matched the UI names. It makes it difficult to develop against in the future by you or others.
A common trick I do to help me organize my script fields, is inside of my MonoBehaviour, I create a small serialized class called (to mimic your system) public class LucesFields. Then I have fields for each one, such as public Light Roja; public Light Verde; etc. Then I create a public field call like this: public LucesFields Luces;
This gives you the header, but also makes the header collapsable. you can name stuff more simply, because if you have Roja field for a UI Slider and a Light, then the header separates it for simplicity. This also reduces junk in Intellisense. Instead of having to find LucesRoja in all of the members in a monobehaviour, you just type Luces (for the lights) then “.R” and intellisense will allready be simplified. I think this might be the better practice.
Don’t get me wrong, I initially loved the helper attribute that @Hunter_Towe suggested above. But after consideration, the fact that it adds a “Magic” layer that hides how to find the variable in the code, I couldn’t agree with it. Pretty, but the type of thinking that will help make code more complicated in the long run. (I mean no offense by that, I have had hundreds of instances like that, and I’m still catching myself doing things like these days)