(How) can I use the [Range] attribute on a [Serializable] class?

I have a class

public class Example : MonoBehavior {

    [Serializable]
    public class SubExample {
        [SerializeField]
        [Range(1,6)]
        private int _Count;
    }

    [SerializeField]
    private List<SubExample> _exampleList;

    [SerializeField]
    [Range(1,6)]
    private int _testRange;
}

In the inspector anyway only the _testRange is displayed as Range while the _Count of the elements of _exampleList are only shown as number.

Am I missing something to get the Range behavior also on the variables in serializable elements of the list?

Tried them the other way round? Maybe this applies to you, I dont know https://answers.unity.com/questions/701700/is-it-possible-to-use-more-than-one-property-attri.html

1 Answer

1

It works just fine for me. What version of unity are you in? do you have any compilation errors? did the script get saved before you let it recompile?

yeah, never mind the mistake was something else apparently. My changes where saved but somehow didn't get updatet in Unity Editor .. now it works suddently ^^

I doubt you put in any effort man. I literally just copied " rotate towards target" from your sentence above, pasted it into google and it came of with The Rotate towards function. https://docs.unity3d.com/ScriptReference/Vector3.RotateTowards.html Which sounds exactly like what you are looking for.