aled96
September 12, 2014, 5:14pm
1
Hi, i want to use this fucntion in script1
if(!IsInvoking("function of script 2"))
Invoke("function of script 2",0.5f);
with a function that is in the script2.
I wrote
if(!IsInvoking(“script.updateScore”))
Invoke(“script.updateScore”,0.5f);
but it doens’t work, what i should do ?
Thank you
P.S. I don’t want to move the function in script1 and use script.variables
rutter
September 12, 2014, 5:20pm
2
If you reference another script object, you can have it call Invoke instead of calling it yourself:
//calls my Foo()
Invoke("Foo", 2f);
//calls some other object's Foo()
someOtherObject.Invoke("Foo", 2f);
As an alternative, you could add a function to the other script that calls Invoke internally:
//in script 1
someOtherObject.DoTheThing();
//in script 2
public void DoTheThing() {
Invoke("Foo", 2f);
}
Coroutines work out the same way. It’s ultimately whichever object that calls Invoke (or StartCoroutine) that ends up owning the context. By default, you’ll call that in your own context, but it’s possible to grab someone else’s and have them call it.