Creating a new object?

Post here your questions about the Unity / .Net / Mono / Windows 8 / Windows Phone 8 API for SFS2X

Moderators: Lapo, Bax

philliamapps
Posts: 6
Joined: 05 May 2012, 18:27

Creating a new object?

Postby philliamapps » 18 Jun 2012, 02:07

Hey all!

So in my unity game I am creating (using sfs2x), I am trying to have a player spawn an object. Is there a way to have this be broadcasted to all the online players? I added a network transform sender, but when I try to use network.instantiate in the code it gives me an error: Failed Network.Instantiate because we are not connected.

When another person has joined, with the network transform sender only on, the spawned object can not be seen.

Any suggestions?
Jake-GR
Posts: 59
Joined: 28 Dec 2011, 22:52

Re: Creating a new object?

Postby Jake-GR » 18 Jun 2012, 05:29

network.instantiate is for the built-in Unity networking, thus it wont work when using SmartFox.
You will need to handle this manually, one way is to create an array/list object (on client) to hold a key-object pair, say like UserID (from SFS) and its associated GameObject (unity). When a client joins, instantiate the GameObject, and then add the UserID-GameObject into the array/list. When a transform message from SFS is received, it sends the UserID, check that against the array/list and move that GameObject.
This is by no means the only way to handle it, but you have to keep in mind the Unity network commands will not do anything. You will need to write your own code to handle sending and receiving messages with SmartFox. There is an Object Movement downloadable example for Unity that uses UserVars to move objects around, I would suggest poking around with that to see how it works.
ThomasLund
Posts: 1297
Joined: 14 Mar 2008, 07:52
Location: Sweden

Re: Creating a new object?

Postby ThomasLund » 19 Jun 2012, 09:15

Yeah - the object movement example is a good place to start.

Once you've got that running and understand it, you can move to the FPS example that uses server side code. But its much more complex as well

/T
Full Control - maker of Unity/C# and Java SFS API and indie games
Follow on twitter: http://twitter.com/thomas_h_lund
philliamapps
Posts: 6
Joined: 05 May 2012, 18:27

Re: Creating a new object?

Postby philliamapps » 08 Jul 2012, 04:13

Hey guys, thanks for the support. I am confused on how one would go about this. I know that the NetworkManager.cs script included in the demo is what is used to communicate with the server, but how could I send location data to the server so that everyone else on it can see it? For example, if I wanted to spawn 1 item (that doesn't move) over the network so that other people could see it, would I need to change the server code, or is there a way to avoid that? Is there a simple function that I could utilize so that I could achieve this? Thanks!
ThomasLund
Posts: 1297
Joined: 14 Mar 2008, 07:52
Location: Sweden

Re: Creating a new object?

Postby ThomasLund » 19 Jul 2012, 07:48

Hi,

Please check the object movement example. It doesnt have server code and does exactly what you ask for

/T
Full Control - maker of Unity/C# and Java SFS API and indie games

Follow on twitter: http://twitter.com/thomas_h_lund

Return to “SFS2X C# API”

Who is online

Users browsing this forum: No registered users and 3 guests