I am trying to build a multiplayer R T S game in U net.
I have the following Build code which attach at Main Camera.
When it can build, it will find the player object to spawn an building.
However, My host can spawn the building.
My client can not spawn the build and even there are no error message.
What is the problem?
R p c Client in player.
When host built. It will call and show to all connected client.
But when client built. It can’t be call. So any one can help me?
public void Build()
{
PreviewObject po = currPreview.GetComponent<PreviewObject>();
if (po.canBuild)
{
Call.canbuild = true;
GameObject.Find("Player").GetComponent<Call>().SpawnBuilding(currBuilding.prefab, currPos, Quaternion.Euler(currRot));
Destroy(previewBuilding);
currBuilding = null;
currPreview = null;
isChoosing = false;
buildingIsHover = false;
}
}
here is the player code.`using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Networking;
public class Call : NetworkBehaviour
{
public Camera camera;
public GameObject game;
public Vector3 vc;
public Quaternion qt;
public static bool canbuild;
public override void OnStartLocalPlayer()
{
this.name = "Player";
// GameObject.Find("Main Camera").GetComponent<CaremaFindPlayerAtStart>().Go();
}
public bool Check() {
if (isLocalPlayer)
{
return true;
}
else return false;
}
[Command]
public void CmdSpawn() {
GameObject game1 = (GameObject)Instantiate(game, vc, qt);
RpcCkech(vc,qt);
NetworkServer.Spawn(game1);
}
[ClientRpc]
public void RpcCkech(Vector3 vc, Quaternion qt) {
print(vc);
}
public void SpawnBuilding(GameObject gb, Vector3 CurrentPos, Quaternion currentRot)
{
if (!isLocalPlayer) return;
game = gb;
vc = CurrentPos;
qt = currentRot;
if (canbuild == true)
{
CmdSpawn();
canbuild = false;
}
}
}
`