Hey!
So I’m working on the network of my game and I encountered a problem (not a big one because I have a solution, but I’m asking for something more… clean, you know!) :
I have a function like this:
public IEnumerator FunctionA() {
// Some code here
yield return StartCoroutine(FunctionB());
// Some code there
}
Something really easy as you can see. The problem is that PhotonView.RPC returns void so I can’t call it using StartCoroutine. The only solution I found it’s to do that:
public IEnumerator FunctionA() {
// Send to the other clients that I called the FunctionB
PhotonView.RPC("FunctionB", PhotonTargets.Others);
// Then do it for myself
yield return StartCoroutine(FunctionB());
}
And I’m not sure it’s the right way… but it works! Do you have any other solutions to solve this? I mean, I don’t want to create a variable and check, by using “while”, if it is true or false, blabla. I don’t want this:
public IEnumerator FunctionA() {
// At the beginning of the function, set _wait to TRUE
PhotonView.RPC("FunctionB", PhotonTargets.All);
// Wait until FunctionB set _wait to FALSE
while (_wait) {
yield return null;
}
}
I don’t even know if it’s gonna work, because I have to go through the server. So, if I want this code works, I have to set the variable _wait to true inside the FunctionA and not FunctionB. Great!
My second issue (and more important) is I can’t send my own classes (which inherits from MonoBehaviour). I have a class named “AObject” which represents every object that the player can interact with (other players, buildings, etc.).
public IEnumerator FunctionA() {
AObject obj = getTarget(...);
PhotonView.RPC("FunctionB", PhotonTargets.All, obj);
}
Unity tells me : “‘AObject’ can not be serialized”. So how I can do that ?
Bonus question: before I started using Unity3D to create my game, I was working on my own server (from scratch) with RakNet (C++). It works and I just need to create all RPCs (some are already created, like the connection).
Is it possible to use this server with Photon in Unity3D ? I don’t know what I’m gonna receive on my server if I send something through Photon/Unity3D.
Thank you!!
PS: Sorry for my english hopefully it’s OK.
Sbizz.