W1thr

SliderColorSetter

Jul 12th, 2021
577
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.51 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5.  
  6. public class SliderColorSetter : MonoBehaviour
  7. {
  8.     [SerializeField] private Slider _slider;
  9.     private Image _image;
  10.  
  11.     private void Awake()
  12.     {
  13.         _image = GetComponent<Image>();
  14.     }
  15.  
  16.     public void ChangeColor()  //Вызывается в событии слайдера OnValueChanged()
  17.     {
  18.         _image.color = Color.Lerp(Color.red, Color.green, _slider.value/ 100);
  19.     }
  20. }
  21.  
Advertisement
Add Comment
Please, Sign In to add comment