- Home /
Changing Hue using slider.
I was wondering how would I change the hue of my entire scene in real time using UI sliders. I want to use it on my ARCamera. Any help would be great. Thank you.
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class shiftHue : $$anonymous$$onoBehaviour { float H=0;
// Update is called once per frame
void Update () {
Color.HSVToRGB(H, 1,1);
}
public void adjustHue (float newHue){
H=newHue;
}
}
Not gonna formally answer, cause I'm to lazy, but it sounds like you want the Post Process stuff
https://docs.unity3d.com/$$anonymous$$anual/PostProcessingOverview.html
Another choice is to have a global hue variable for all shaders in the game, meaning your game needs to use custom written shaders and not the Unity prebuilt shaders.
https://docs.unity3d.com/ScriptReference/Shader.SetGlobalFloat.html
Answer by dishant27 · Feb 28, 2018 at 09:26 AM
using UnityEngine;
using System.Collections;
using UnityEngine.UI; // Required when Using UI elements.
public class Example : MonoBehaviour
{
public Slider mainSlider;
public Light directionalLight;
float H, S, V;
public void Start()
{
Color.RGBToHSV(directionalLight.color, out H, out S, out V);
//Adds a listener to the main slider and invokes a method when the value changes.
mainSlider.onValueChanged.AddListener(delegate {ValueChangeCheck(); });
}
// Invoked when the value of the slider changes.
public void ValueChangeCheck()
{
directionalLight.color = Color.HSVToRGB(mainSlider.value,S,V); //removed new from here
Debug.Log(mainSlider.value);
}
}
// Also provide the reference to light and slider to the gameobject where you'll attach this script. ***Edited my answer including @Harinezumi's answer
@dishant27 , is this what you wanted to do?
float H, S, V;
Color.RGBToHSV(directionLight.color, out H, out S, out V);
directionalLight.color = Color.HSVToRGB(mainSlider.value, S, V);
Admittedly, google doesn't give you results with Color.RGBToHSV(), only the other way around.
Answer by AnandAshar · Mar 01, 2018 at 06:41 AM
Nothing happens when I run the code. I dropped the script to the ARCamera, then included the object in the slider and called the function. I' m not sure if I did it right. I'm new to unity and a step wise procedure would help me a lot. @Harinezumi @dishant27
1) Attach the above script to camera. (removed "new" keyword from line 21) 2) In inspector, drag and drop light source of your scene in the directionalLight field of script. 3) Then, drag and drop UI component slider in the mainSlider field of script. 4) Play & check the Hue value of the light Source in the editor by moving the handle of the slider.
@dishant27 I did that. But it doesnt change anything in the game mode. Although I can see the color of directional light being changed in the inspector..since I am using an ARCam (vuforia) nothing happens. Any help with that?
Because your RGB value of directional light color are near to 255. $$anonymous$$ake all them under 100, you'll find the significant variation with slider. Also keep a cube in screen to see how it's affecting the gameobjects.