how to assign a single value to a key for an object ?(if this? else this?)

i want to assign a single key to do a action for my object (in this case … it’s color change …
my code simple code is …

	if (Input.GetKeyDown (KeyCode.R)) {
		gameObject.GetComponent<Renderer> ().material.color = Color.red;
	} else if ()

		{
			.gameObject.GetComponent<Renderer> ().material.color = new Color (0.5f,1,1)	 ;
		}

Thanks in advance…

That’s just about the best you can do. If you had to do this a LOT then you might try to get a bit more clever:

private Dictionary<KeyCode, Color> m_KeyColors = new Dictionary<KeyCode, Color>();

private Awake(){
    //Add a line like this for every key you need
    m_KeyColor.Add(KeyCode.R, Color.red);
}

private void Update(){
    if (Input.anyKeyDown){
        foreach(KeyValuePair keyColor in m_KeyColors){
            if (Input.GetKeyDown(keyColor.Key))
                gameObject.GetComponent<Renderer>().material.color = keyColor.Value;
       }
    }
}