is this possible?

I have two script. I want to send from a script “A” information to another script “B” for processing and then return it to the script “A” and continue with the code. Thx.

Script A

IEnumerator MakesomethingA ()
{
yield return new WaitForSeconds(1.0f);

ScriptB.MakesomethingB
"wait while the information is processed in the script B "



}

Script B

IEnumerator MakesomethongB ()
{
yield return new WaitForSeconds(1.0f);"


Return Value to script A

}

Unless you get a reference to it using GetComponent() or similar you’ll need to make the function static so you can access it, if you want to send variables you would need to change your code to:

IEnumerator MakesomethingA ()
 {
 yield return new WaitForSeconds(1.0f);
 ..........
 ScriptB.MakesomethingB [COLOR="#FF0000"]("hello");[COLOR]
"wait while the information is processed in the script B "
 ......... 
......... 
.........
 }
 

Script B
 
IEnumerator MakesomethongB ([COLOR="#FF0000"] string text[/COLOR] )
 {
 yield return new WaitForSeconds(1.0f);"
 ..........
 ..........
 [COLOR="#FF0000"]return text;[/COLOR]
 .........
 }

You can also use a script, as a variable. This will skip the need for getComponent or a static var.

someScript someScriptObj;
someScriptObj.DoThis();

Ok thx , My big question is once the script “B” does the job to send the information to the script “A” the best method is a static variable?

There’s no need for a static variable and if the only reason you want to use it is to address an access issue then you shouldn’t use it.

This is probably the most inflexible version of a solution.

public class A : MonoBehaviour
{
    private B bee;

    void Start()
    {
        bee = GetComponent<B>();
    }

    public IEnumerator DoStuff()
    {
        yield return new WaitForSeconds(5);
        int c = bee.Calculate(2);
        Debug.Log(c);
    }
}

public class B : MonoBehaviour
{
    public int Calculate(int lhs)
    {
        return lhs + 5;
    }
}

Ok Thx¡¡.