revival/game/Assets/Scripts/Settings/PlayerPrefSlider.cs

27 lines
605 B
C#
Raw Normal View History

2021-03-08 17:26:33 +01:00
using System;
2021-03-08 16:13:19 +01:00
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
2021-03-08 17:26:33 +01:00
using UnityEngine.UI;
2021-03-08 16:13:19 +01:00
2021-03-08 17:26:33 +01:00
[RequireComponent(typeof(Slider))]
2021-03-08 16:13:19 +01:00
public class PlayerPrefSlider : MonoBehaviour
{
2021-03-08 17:26:33 +01:00
private Slider _slider;
[SerializeField]
private PlayerPrefValue _playerPref;
private void Awake()
2021-03-08 16:13:19 +01:00
{
2021-03-08 17:26:33 +01:00
_slider = GetComponent<Slider>();
_slider.onValueChanged.AddListener( _playerPref.SetFloat );
2021-03-08 16:13:19 +01:00
}
2021-03-08 17:26:33 +01:00
private void OnEnable()
2021-03-08 16:13:19 +01:00
{
2021-03-08 17:26:33 +01:00
float value = _playerPref.GetFloat();
_slider.SetValueWithoutNotify( value );
2021-03-08 16:13:19 +01:00
}
}