- Home /
RPC Call problem 1 gameobject 1 prefab
Hello,
I can't explain this myself so I have need little bit help. I have 2 things. One prefab.. which is player with scripts for movement and a script "controller" which sends via RPCs inputs to the server. The other thing is a empty gameobject "spawnpoint" has a script "AuthPlayerhandler". The playerhandler script does work with things example player joining, put it to lists, and send to players.. if he does request spawn, then send to others. And also has the "OnInput" RPC function. But my problem is.. the player prefab has controller.cs. There is also the OnInput RPC Function. So it means they are not in same script.
How could I clear this?
My I idea was to make public gameobject variable. But then my Spawnpoint need a prefab. When I do this.. I get error like "SceneID: 1 ..." bla bla.
Code controller.cs in Playerprefab
public GameObject playerHandler;
void Update() {
if(Network.isClient) {
if(Input.GetAxis("Vertical") > 0) {
playerHandler.GetComponent<AuthPlayerhandler>().networkView.RPC("OnInput", RPCMode.Server, Network.player, "Vertical", (Input.GetAxis("Vertical")));
}
}
}
AuthPlayerhandler.cs
[RPC]
void OnInput(NetworkPlayer player, string input, float val)
{
Debug.Log("Got Input from Player: " + player + ". Input: " + input + " Value: " + val);
Playerclass playerInstance = getPlayerInstance(player);
//Debug
if(input == "Velocity") {
playerInstance.Velocity = val;
}
if(input == "Steer") {
playerInstance.Steer = val;
}
}
EDIT: Wanted say Spawnpoint gameobject is in hierarchy. Playerperfab will spawn when player request spawn
Please properly format your code andI'll answer your question