I appreciate anyone who reads this and has the time to point me in the right direction. I have looked at the Leepo tuts, the Unity resources, Unity Answers/Wiki and literally started at the back of these forums went through all relevant networking posts and I still don’t get it. I feel I’m close, and then my code just doesn’t do what I need it to. I’m trying to create a very simple example to get started in networking, but to no avail! Below is a description of what I’m trying to do, maybe someone can get the light to “turn on” for me! Thanks again.
In my Unity scene I use the connect script from the Leepo tutorial to display the connection option and start the server, this is attached to the camera. Also attached to the camera is a Spawn Script (also from Leepo) that spawns the player using Network Instantiate.
The player prefab itself has a Network View component, watching it’s transform and using no Serialization, and a script for moving, showing a GUI, etc. Inside that script, on the Awake function, it checks to see if the NetworkView.isMine and enables/disabled the script accordingly - all straight from the Leepo Tut, old version, not current Asset Store one. Inside the player’s script is code to print it’s Player Number and Network View ID to it’s GUI.
When I start the sever in the editor, I get a player instantiated, and it gives a GUI showing “Player Number : 0 Network ID: AllocatedID: 1”. Next I load up the client executable, connect and get “Player Number : 1 Network ID: AllocatedID: 150”. Right now, from the reading, I assume the Network Instantiate is giving out the Network View Ids. Right? I also take away that a gameobject can only communicate to other instances of itself on it’s Network View. Right?
The simple example I want to get working is this: Each player’s GUI shows the same text:
“You have fired X number of bullets”
“Your opponent has fired X number of bullets”
I can get each player to correctly update the “You have fired X number of bullets” (each player updating his own variable “yourFire” when “fire1” is pushed, but I have not gotten the “Your opponent has fired X number of bullets” to update. What I have tried to do to update the otherFire variable is RPC calls to the other player sending the updated value yourFire and putting it in the other player’s otherFire variable. I have attempted every combination of RPC, player number, etc to get the two talking, but I am at a loss. I can connect my client, player 1, and see it’s player instance on the server, I can see the RPC call being made on it, but never on the player created on the server - player 0.
Do these players, when Instantiated, need to be forced into the same Network View to be able to “see” and talk to each other? If so, what is a simple method to do this? I’m sure this is easy, but I’ve been looking at this “magic eyes 3d” puzzle all week and have yet to see anything come into focus!!!
Any help, comments, suggestions, etc. much appreciated! I have reached the end of my “artist” programmers knowledge!
TheLorax