How do I repeat a part of my script?

I want to repeat a part of my code:

function Start(){ 
    guiText.material.color.a = 0;
    yield WaitForSeconds(3);
        FadeIn();
        }  
function FadeIn(){
    while (guiText.material.color.a < 1){
       guiText.material.color.a += 0.1 * Time.deltaTime * 10;
       yield;    
       }  
       yield WaitForSeconds(0.1);
       FadeOut();  
       }
 
function FadeOut(){
    while (guiText.material.color.a > 0){
       guiText.material.color.a -= 0.1 * Time.deltaTime * 10;
       yield;    
       }
}    

I want to repeat the “FadeIn” and “FadeOut” parts, how will I be able to do that? I tired StartCoroutine, but it was just to difficult…

Just make a

    function Update() 
    { 
      FadeIn(); 
      FadeOut(); 
    }

Replace the while loop to a if statement. Also remove FadeOut () from the FadeIn (), thats no longer needed.

Have you thought about putting them both in one function instead of two?

Another thing you can do and its reallly simple is using Mathf.PingPong. See below:

Heres a reallllly simple solution:

public class TextFader : MonoBehaviour
{
    public GUIText text;
    public float speed = 1f;
    public Color color;

    void Start () 
    {
        if(text == null)text = this.gameObject.GetComponent<GUIText>();
        if(text == null)Debug.Log("Please attach this script to a gameobject with a GUIText component or assign one manually to this.");

    }

    void Update ()
    {
        if (text != null)
        {
            text.color = color;
            color.a = Mathf.PingPong(Time.time / speed, 1);
        }
    }
}

Or

function FadeIn(){
    while (guiText.material.color.a < 1){
       guiText.material.color.a += 0.1 * Time.deltaTime * 10;
       yield;    
       }  
       yield WaitForSeconds(0.1);
       FadeOut();  
       }
 
function FadeOut(){
    while (guiText.material.color.a > 0){
       guiText.material.color.a -= 0.1 * Time.deltaTime * 10;
       yield;    
       }else{
       FadeIn();
      
    }
}