- Home /
Question by
TotalAnnihilation · Jun 21, 2016 at 08:14 PM ·
networkingmultiplayerunity5parentinginternet
Parenting via Networking
Hello there,
I am making a game in which I got a player inside a moving space ship. When the ship moves, the player moves too. I accomplished that by parenting the player to the ship. On the other clients, of course, the player is laggy/glitch, that is why I want to have the players parented to the ship on all the clients. I don't really get this to work, here is what I've got:
//this one is on the space ship
import UnityEngine.Networking;
public class parentingScript extends NetworkBehaviour{
function OnTriggerEnter(coll: Collider){
if(!isServer)
return;
if(coll.gameObject.tag == "Player")
coll.gameObject.GetComponent(Character_Interact).RpcParent(this.gameObject, coll.gameObject, true);
}
//this one is on the character
@ClientRpc
function RpcParent(parentgO: GameObject, gO: GameObject, prnt: boolean){
print(gO.name);
print(parentgO.name);
if(prnt)
gO.transform.parent = parentgO.transform;
else
gO.transform.parent = null;
}
This works so far, but this doesn't parent the players when new players enter the game. For example:
1 joins, 1 is parented.
2 joins, 2 is parented on 1 and 2, but 1 is not parented on 2.
3 joins, 3, is parented on 1,2,3, 2, but 2 is not parented on 3.
I hope you get what I mean, any help will be truly appreciated! Thanks! :-)
Comment