Fade out top line of GUILayout.Label. C#

Hi everyone, I’m currently working on creating a GUILayout.Label that grabs a string and types it out character by character until it fills a GUILayout area.

For string dialogue, the GUILayout executes:

Type (dialogue);
GUILayout.Label (typingDialogue, dialogueStyle);

Which calls the coroutine “TypeDialogue” if the boolean “Type” is not currently active:

    //This boolean starts the TypeDialogue coroutine only if it is not currently typing.
	public bool Type (string dialogue) {
		if (typing)
			return false;
		StartCoroutine(TypeDialogue(dialogue));
		return true;
	}
	
	//This section scrolls the dialogue text like an old-fashioned RPG.
	IEnumerator TypeDialogue (string typeDialogue) {
		
		typing = true;
		for (int i = 0; i <= typeDialogue.Length; i++) {
			typingDialogue = typeDialogue.Substring(0, i);
			yield return new WaitForSeconds (0.05f);
		}
		typing = false;
	}

Because some of the dialogue strings are quite long, I’m working on a way to break the dialogue into multiple labels (one per line), so that I can fade out the top one once I’ve reached a certain number of lines.

Has anyone worked with this before? My current goal is to stop adding characters to a label once the label has reached the GUILayout area width and then create a new label starting where the last one left off.

If you’re simply asking how to fade text, I’m pretty sure you can just set the alpha of the GUI:

Color oldColor = GUI.color;
GUI.color = new Color(oldColor.r, oldColor.g, oldColor.b, oldColor.a / 2.0f);

// Draw label here

GUI.color = oldColor;