RPC calling: networkView.RPC("Spawn",RPCMode.AllBuffered... RPC function: [RPC] private void Spawn(...) { } Problem is that when other player join to game. Then becomes an error that says that "Spawn" doesn't exist in a other script that haves [RPC] functions too. Both have Network view on them. THIS ALREADY SOLVED NEW PROBLEM BELOW
OK, give us a bit more code here please. It is hard to tell what is going wrong when you just post a partial of your code. *Just a note, when asking for help; it is better to give too much information than not enough
Here is more code: It begins like this: Code (csharp): using UnityEngine; using System.Collections; public class PlayerSync : MonoBehaviour { RPC call: Code (csharp): if (GUI.Button(new Rect(0,0,80,20),"Button")) { networkView.RPC("Spawn",RPCMode.AllBuffered,unitselected,public_player_position,value1); } Method in same code: Code (csharp): [RPC] private void Spawn(int unitselected2,Vector3 location,int value) { ... } ERROR when other player presses spawn button(not when self): RPC call failed because the function "Spawn" does not exist in any script attached to "Chat" PS. Can the RPC call send many values or do I have to do it a other way?
I got that fixed, but there is a new problem. When the button is pressed it creates both players new instances. Example: Player creates box. He sends RPC call to create box, but it creates a box to every player location. RPC calling is the same. Code (csharp): [RPC] private void Spawn(string values) { Network.Instantiate(object1,Vector3.zero, Quaternion.Euler(Vector3.zero), 0); } A photo of the bug:
I don't think you get the idea of what networking is.. RPC's are Remote Procedure Calls.. this means they are called on each system. When you are create something in the RPC, it will be created in each instance.. as this is what it is supposed to do. My suggestion to you at this point is to read as many tutorials as you can, and wrap your head around what networking is about, and why things work the way they do. Once you understand the theory, what you are trying to do might make more sense. Maybe it might be better for you to explain exactly what it is you are trying to do?
I want them to be called on each system. So that every player sees the created box. Problem is that it creates boxes for every player. So when there is 1 player it creates 1, but when there is 2 creates 2 boxes when it should make only 1. (This was before these problems). There is always only 1 object that haves this code. This object haves networkview component. EDIT: If I turn off the networkview component it makes errors becouse it doesn't exist, but it creates the objects the way I want. Any ideas? (Object won't get any sent values)
network instantiate instantiates against all clients.. you call the RPC in a buffered state.. player 1 pushes button, RPC is called to instantiate network object (creates buffered on all systems) player 2 gets the RPC call and instantiates network object (that also creates an object on each system) etc.. The problem is this.. you are using an RPC call that does another network call.. try just calling the network instantiate from the button press.. BAM, problem solved. Take the time to sit down and understand what is going on here, like I suggested above. Don't just jump to the forums when you are having the slightest problem. Also as a note.. instead of Quaternion.Euler(Vector3.zero), do Quanternion.Identity
Yeah I figured it out too. I have just started using RPC calls, but now I have one problem. I need to set some values to the created object. Code (csharp): GameObject Box = Network.Instantiate(GameObject.FindGameObjectWithTag("MainCamera").GetComponent<ConnectionScript>().Box, Vector3.zero,Quaternion.identity, 0) as GameObject; Box.GetComponentInChildren<Controller>().value1=value2; How can I turn this into RPC or something like that so that other players get the values too?
i am having a similar issue that i cant quite figure out ... what i did is iv put a script on the player prefab that says i.. if collision.gameObject.name == "server player " .. debug.log(ismine) , else if collision.gameObject.name == "client player " .. debug.log(ishis) ...... This is working out when the player collides with the clients player ... but is not working out vice versa .. its like no collision is being detected.. PLEASE HELP iv been stuck on this for a week ! I am ready to pay for some help.