Search Unity

How To StartCoroutine in another behavior for a different GameObject?

Discussion in 'Scripting' started by Rick-Gamez, Mar 29, 2015.

  1. Rick-Gamez

    Rick-Gamez

    Joined:
    Mar 23, 2015
    Posts:
    218
    Hey all I'm kinda new to C# and was wondering how to StartCoroutine in another behavior that's attached to a different GameObject. I already have A GameObject var to indicate the other object.

    Thanks in advance.
     
    Last edited: Mar 29, 2015
  2. lineupthesky

    lineupthesky

    Joined:
    Jan 31, 2015
    Posts:
    92
    It should be just like calling a function from another script. Someone correct me if I'm wrong though:

    Script1.cs

    Code (CSharp):
    1. public IEnumerator Timer()
    2. {
    3. //content
    4. yield return null;
    5. }
    Script2.cs
    Code (CSharp):
    1. public Script1 _Script1; // attach the gameobject that has Script1 via inspector
    2.  
    3. StartCoroutine(_Script1.Timer());
     
  3. Rick-Gamez

    Rick-Gamez

    Joined:
    Mar 23, 2015
    Posts:
    218
    Cool I'll try that thanks a bunch.