I am new to networking with unity. I am curious about sending what I think is a basic RPC, in which I want to change a variable (health) on collision. I am prototyping a FPS type experience, for now there is only 2 players, a server and a client. So the example for the RPC can go to "others" I think. Here is my code with no networking, how can I make this into an RPC and have it effect the client? Code (JavaScript): function OnTriggerEnter (other : Collider) { if (other.gameObject.tag == "Other_Player") { Enemy(); } }// END OnTriggerEnter function Enemy () { var enemy = GameObject.FindWithTag("PlayerBodyMesh").transform; enemy.GetComponent.<Player>().playerHealth -= 20; }
After the client is connected to server, i think you can use that Code (CSharp): function OnTriggerEnter (other : Collider) { if (other.gameObject.tag == "Other_Player") { Enemy(); } }// END OnTriggerEnter function Enemy () { var enemy = GameObject.FindWithTag("PlayerBodyMesh").transform; float damage = -20; GetComponent<NetworkView>().RPC("DamageReceived", RPCMode.OthersBuffered, damage); } [RPC] void DamageReceived(float damage) { enemy.GetComponent.<Player>().playerHealth += damage; } i think this is what you're looking for...