Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Voting for the Unity Awards are OPEN! We’re looking to celebrate creators across games, industry, film, and many more categories. Cast your vote now for all categories
    Dismiss Notice
  3. Dismiss Notice

Starting a Coroutine from another scrypt

Discussion in 'Scripting' started by Nuubzz, Dec 1, 2018.

  1. Nuubzz

    Nuubzz

    Joined:
    Aug 14, 2018
    Posts:
    31
    Hi,

    Basicly I have a coroutine in a scrypt but I'd like to be able to start it from another scrypt.
    Could anyone help me do that ?

    Thanks
     
  2. Lurking-Ninja

    Lurking-Ninja

    Joined:
    Jan 20, 2015
    Posts:
    9,900
  3. Nuubzz

    Nuubzz

    Joined:
    Aug 14, 2018
    Posts:
    31
    I tried, and it gives me an error message saying "An object reference is required to access non-static member 'scryptname.coroutinename' "

    I didn't know what to do from there so I asked on the forums
     
  4. Lurking-Ninja

    Lurking-Ninja

    Joined:
    Jan 20, 2015
    Posts:
    9,900
    I really hate when people don't want to do their own homework.

    Here is what you need to do:

    - get the reference of the other object in the script you want initiate the call from
    - if you call this reference variable otherScript
    - then you can write otherScript.methodName();
    - in this methodName in the other script initiate the coroutine

    Of course as soon as you post your code here in code tags and explain what have you already tried, maybe we can help more. But don't expect us writing your code.
     
    Antypodish likes this.
  5. Nuubzz

    Nuubzz

    Joined:
    Aug 14, 2018
    Posts:
    31
    Great it worked,

    Thanks a lot next time I'll do my homework :)
     
    Lurking-Ninja likes this.
  6. Lurking-Ninja

    Lurking-Ninja

    Joined:
    Jan 20, 2015
    Posts:
    9,900
    Good! And when you have concrete questions, feel free to post your code here and ask!