Set RangeAttribute to specific numbers


Currently i have found out about RangeAttribute. Now this will work great, but there is one drawback unfortunately.

I would like to set the range to be specific numbers like: 0, 2, 4, 8

So there is a total of 4 values that the range can be.

Is there any way to conquer this for a public variable? Having the slider be either 0, 2, 4, 8?

Or should i be using something different? I just want to constrict the integer to those values.

Thanks in advance! Also using c#!

public int antiAliasingAmount ;

If your field is conceptually only a limited set of values with strict borders, I would strongly recommend to use what’s specifically designed for that purpose — enums. Also you can also back enums by integers and then cast. It’s not as “cool” as a slider, but does the job.

using UnityEngine;
using System.Collections;

public class Test : MonoBehaviour
	public enum Antialiasing
		Zero = 0,
		Two = 2,
		Four = 4,
		Eight = 8
	[SerializeField] private Antialiasing _antialiasing;