Reputation: 283
I have a problem with a variable which is not showing up in the inspector even though I have declared it a serialized field.
Code:
using System;
using UnityEngine;
using UnityEngine.UIElements;
public class SettingsPopup : MonoBehaviour
{
[SerializeField] private Slider speedSlider;
private void Start()
{
speedSlider.value = PlayerPrefs.GetFloat("speed", 1);
}
....
}
I am using Unity 2019.2.10f1 Personal.
edit: changing the type of speedSlider to anything outside the UnityEngine.UIElements namespace makes it appear in the inspector.
Upvotes: 0
Views: 6969
Reputation: 3058
If you want a slider for the UI control, an attribute needs to be used to decorate the field, e.g. [Range(1, 100)]
. The way the code is written it is asking the editor to use a control that allows the user to provide something of type Slider
for the field value, rather than the intended float
.
This will show a slider control in the editor:
[Range(1.0f, 100.0f)] public float speed;
Upvotes: 1