Slider change color.g.r.b

How can I change the color color.b color.g color.r color.a with a slider already present??47948-unity-problem.gif

This is the script that change the color with the keywords:R,G,B,A

using UnityEngine;
using UnityEngine;
using System.Collections;

public class colored : MonoBehaviour {
	
	public Color altColor = Color.black;
	public Renderer rend; 
	
	void Example() {         
		altColor.g = 0f;         
		altColor.r = 0f;        
		altColor.b = 0f;         
		altColor.a = 0f;     
	}      
	
	void Start ()
	{       
		
		Example();
		
		rend = GetComponent<Renderer>();
		//Set the initial color (0f,0f,0f,0f)
		rend.material.color = altColor;
	}      
	
	void Update() 
	{
		if (Input.GetKeyDown (KeyCode.G)){  
			altColor.g += 0.1f;
			rend.material.color = altColor;
		}
		if (Input.GetKeyDown (KeyCode.R)){             
			altColor.r += 0.1f;
			rend.material.color = altColor;
		}
		if (Input.GetKeyDown (KeyCode.B)){         
			altColor.b += 0.1f;
			rend.material.color = altColor;
		}
		if (Input.GetKeyDown (KeyCode.A)){          
			altColor.a += 0.1f;
			rend.material.color = altColor;
		}
	}         
}

Hi,

First of all you need to use the UI library to be able to reach easily your sliders !

using UnityEngine.UI;

Make some public sliders to be able to link them with drag and drop:

public Slider greenSlider;
//...

Now you want the value of your slider to be equal to the color:

altColor.g = greenSlider.value;

And that’s it ^^
If you want the color to change as soon as you move the slider, put your code into Update ; otherwise, create a public function that changes the color(s) and call it wherever you want through script or button :slight_smile: