C# CoRoutine with GameObject Parameters

Hi,

In one script file I have two prefabs that I instantiate individually based on certain conditions. Is it possible to pass these GameObjects in as Paramaters and instantiate them in a differently named script file?

Script File 1:

    public class Player : MonoBehaviour 
    {
// Allow our PlayerClass awareness
public GameObject Go1;
public GameObject Go2;  </p>
      StartCoroutine(DoSomething(Go1, Go2));
   }

Script File 2:

public class Player2 : MonoBehaviour { public int IEnumerator DoSomething(GameObject Go1, GameObject Go2) { // Do something with Go1 and Go2 return 0; // and return an int } }

Im getting parsing errors when trying to return an int, and object reference erros for the nonstatic field, method or properties.

You should be able to use those GameObjects in the Coroutine if they are instantiated in another file before the function is called. However you should check for null before using them.

There were some syntax errors in your post, here are corrections:

Script File 1:

public class Player : MonoBehaviour 
{
    // Allow our PlayerClass awareness
    public GameObject Go1;
    public GameObject Go2;  

    public void Update()
    {         
       StartCoroutine(Player2.DoSomething(Go1, Go2));
    }
}

Script File 2:

public class Player2 : MonoBehaviour 
{
    public static IEnumerator DoSomething(GameObject Go1, GameObject Go2)
    {
        if (Go1 != null && Go2 != null)
        {
            //do stuff
        }

        yield return 0; 
    }
}