- Home /
How can I instantiate an Orthello prototype with the Network class?
I've worked with Orthello framework for some time now and I've decided to start coding a small multiplayer game to test out Orthello + Network.
The thing is, when it comes to spawning the player, I have a prototype which is an OTAnimatingSprite which can't be instantiated with the following line of code:
Network.Instantiate(playerPrefab, transform.position, transform.rotation, 0);
In the line above, playerPrefab is a prototype that I dragged from my OT list of prototypes to a public gameObject variable in the Inspector that I declared in the NetworkManager.cs script. However, this does not work. It returns error "Cannot implicitly convert OTAnimatingSprite to GameObject", which makes sense because the prototype is an OTAnimatingSprite and the playerPrefab variable is just a GameObject.
Normally prototypes are instantiated in Orthello using the following line:
OT.CreateSpriteAt("stringPrototype", vectorPos);
Is there any way I can walk the path of light again or is Orthello just not compatible with Unity's Network class at all?
Thanks for your answers,
Pzeronow
I haven't really worked with Orthello, but i assume you can use RPCs to send the Instantiating parameters to the other player and have them Instantiate their clientside prefab from it.
Answer by pzeronov · Jun 19, 2014 at 07:34 AM
I already figured it out. I can use Network.Instantiate just as I described on the question itself, the only problem is that I have to manually assign the container and the animation (if it's an OTAnimatingSprite) or the texture (if it's just an OTSprite) on the object script on Awake(). Long story short:
Create a prefab out of your Orthello prototype.
Assign it in the inspector to a public GameObject variable in the script that will instantiate the object.
Instantiate the object as you would normally do using Network.Instantiate.
On the object's script on Awake(), programatically assign the container and animation of the OTAnimatingSprite by accessing the OTAnimatingSprite component of the prefab as follows:
prefabSprite.GetComponent<OTAnimatingSprite>().container = OT.ContainerByName("prefabSprite-Container"); prefabSprite.GetComponent<OTAnimatingSprite>().animation = OT.ContainerByName("prefabSprite-Animation");
In case you're working with a OTSprite, you should do the same thing and on Awake() just assign a public Texture2D to the image property of the prefab that was instantiated using Network.Instantiate:
prefabSprite.GetComponent<OTSprite>().image = textureImage;
If you don't do any of this, the object will actually instantiate, but the animation, container and image properties will be empty, thus resulting in the object not appearing on scene.
Hope this helps anyone trying to use Orthello for an online multiplayer game.
Your answer
Follow this Question
Related Questions
Unet NetworkServer.Spawn() not working 5 Answers
My energy bar decrease only on the host screen with network 0 Answers
Network.Instantiate Problem 1 Answer