I implemented the CustomText (it only extends UnityEngine.UI.Text) and CustomTextEditor which changes text color when button is pressed (script below):
using UnityEditor;
using UnityEditor.UI;
using UnityEngine.UI;
[CustomEditor(typeof(CustomText))]
public class CustomTextEditor : TextEditor
{
public override void OnInspectorGUI()
{
base.OnInspectorGUI();
Text component = (CustomText)target;
if(UnityEngine.GUILayout.Button("Change color"))
{
if (component.color == UnityEngine.Color.green)
component.color = UnityEngine.Color.red;
else
component.color = UnityEngine.Color.green;
}
}
}
When I press a “Change color” button in the Inspector I can see that color changes but it doesn’t apply in the scene. As it is shown in the image, the “color” variable is green now but the text is actually red:
If I do any action in the Editor (e.g. click on the “color” field, disable/enable any game object in the scene) a color of the text will change. It changes right away also when game is in the playing mode. What could be the cause of this behavior? Is there any way to change text color when I press the button?
Thank you for any help,
Damian
No sorry, I can't set it like that. I need to pass the actual pointer to the value so I can set it IN the method dynamically. barRef.publicProperty does not let me set barRef.publicProperty2 within the same method. So: Method(//The refrence to the bar.publicproperty)
– jmgek