Type could not be resolved because of a cycle.

Just added the bottom part of the code so I can check to see of a object is destroyed or not. but im getting this error :

Assets/Scripts/Mission.js(61,9): BCE0070: Definition of ‘Mission.Check()’ depends on ‘Mission.Wait1()’ whose type could not be resolved because of a cycle. Explicitly declare the type of either one to break the cycle.

Im not great at code so any help on where i went wrong would be good as I am learning.

#pragma strict
 
var enemyPrefabs : GameObject[]; // Array of different Enemies that are used.
var spawnPoints : Transform[];  // Array of spawn points to be used.
var Name1Choices : String[] = ["Bob", "Mary", "Maxo","Phil","Noobas","Hervard","Dan","Daniel","Johnathan"]; 
var Name2Choices : String[] = ["Berry", "Richards", "Stephens"];
var Backstory1Choices : String[] = ["Was"];
var Backstory2Choices : String[] = ["a"];
var Backstory3Choices : String[] = ["gent"];
var Name1;
var Name2;
var Backstory1;
var Backstory2;
var Backstory3;
var Nameone : GUIText;
 
var mission : boolean = false;
var money : float;
 
function Start () 
{
    MissionGen();
}
 
function MissionGen () 
{
    if( !mission )
    {
       var pos :  Transform = spawnPoints[Random.Range(0, spawnPoints.length)];  // Randomize the spawnPoints to instantiate enemy at next.
       var obj : GameObject = enemyPrefabs[Random.Range(0, enemyPrefabs.length)];
       Instantiate(obj, pos.position, pos.rotation); 
 
       	Name1 = Name1Choices[ Random.Range( 0, Name1Choices.length ) ]; //Randomly Generated Name
      	Name2 = Name2Choices[ Random.Range( 0, Name2Choices.length ) ]; //Randomly Generated Name Part 2
       	Backstory1 = Backstory1Choices[ Random.Range( 0, Backstory1Choices.length ) ]; //Randomly Generated BackStory Part 1
       	Backstory2 = Backstory2Choices[ Random.Range( 0, Backstory2Choices.length ) ]; //Randomly Generated Backstroy Part 2
  		Backstory3 = Backstory3Choices[ Random.Range( 0, Backstory3Choices.length ) ]; //Randomly Generated Backstory Part 3
       	mission = true;
       	Nameone.text = Name1;
       	Wait1();
    }
    else
    {
       Invoke( "MissionGen", 1.0f );
    }
}
 
function Check () 
{
    var BadGuyCheck : GameObject = GameObject.FindGameObjectWithTag( "BadGuy" );
    if ( BadGuyCheck == null )
    {
       mission = false;
       money += Random.Range(1000,10000);
       yield WaitForSeconds (1);
       Invoke( "MissionGen", 1.0f );
    }
    else
    {
    	yield WaitForSeconds (1);
    	Wait1 ();
    }
}

function Wait1 ()
{
	yield WaitForSeconds (1);
	Check ();
}

The way you use coroutines is very strange. You kind of build a recursive chain but since you have a yield in each one it’s not a conceptional problem. However a coroutine is not a method, it’s an object with it’s own class type. The compiler just can’t generate the code for both classes since they depend on each other. The actual type is not known until the class has been generated.

I would suggest something like this:

function MissionGen ()
{
    while(true)
    {
        var pos : Transform = spawnPoints[Random.Range(0, spawnPoints.length)]; 
        var obj : GameObject = enemyPrefabs[Random.Range(0, enemyPrefabs.length)];
        Instantiate(obj, pos.position, pos.rotation);
        Name1 = Name1Choices[ Random.Range( 0, Name1Choices.length ) ];
        Name2 = Name2Choices[ Random.Range( 0, Name2Choices.length ) ];
        Backstory1 = Backstory1Choices[ Random.Range( 0, Backstory1Choices.length ) ];
        Backstory2 = Backstory2Choices[ Random.Range( 0, Backstory2Choices.length ) ];
        Backstory3 = Backstory3Choices[ Random.Range( 0, Backstory3Choices.length ) ];
        mission = true;
        Nameone.text = Name1;
        yield WaitForSeconds (1);
        while (!Check())
        {
            yield WaitForSeconds (1);
        }
        yield WaitForSeconds (1);
    }
}
 
function Check()
{
    var BadGuyCheck : GameObject = GameObject.FindGameObjectWithTag( "BadGuy" );
    if ( BadGuyCheck == null )
    {
        mission = false;
        money += Random.Range(1000,10000);
        return true;
    }
    return false;
}

This does exactly the same but don’t start new coroutines all the time.