- Home /
How to WAIT for RPC to return/finish?
I'm working on an online, 1 vs 1 game, and have one spot in my code set up like this:
int enemyLeaderIndex;
Start()
{
//RPC Call to set the OTHER PLAYER's enemyLeaderIndex
Debug.Log("Enemy's leader is: " + allLeaders[enemyLeaderIndex]);
}
Obviously RPC's have lag, which will change from computer to computer, but just can't run as fast as the normal, not-online code. So is there a way to make my code WAIT until that RPC call is finished? I know RPC's can't return a value, but I'm unsure if simply waiting a frame ("yield return null") will be enough even on slower connections, or how wait for the RPC reliably
Answer by Anymeese · Jan 21, 2015 at 06:10 AM
I figured it out. I set up the code like this (again keeping it as simple as possible):
int enemyLeaderIndex = -1;
Start()
{
//RPC Call to set the OTHER PLAYER's enemyLeaderIndex to a value of 0 or greater
}
Update()
{
if(enemyLeaderIndex > 0 && haventAlreadyDoneThisYet)
{
doStuff();
}
}
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Make enemy wait before attacking player 2 Answers
When does Instantiate return ? 2 Answers