I am making a 3D multiplayer fps game and when I spawn, I can see my own crosshair, which is good, but I can also see other people’s crosshair. If I toggle the visibility of the crosshair in culling Mask in camera, then I can either see no one’s crosshair, or everyone’s crosshair. This is because, I add “Don’t see” layer to the crosshair, and when another user comes his crosshair also has the layer “Don’t see”.
I set it such that the camera can not see any crosshair, then I do this :
if (isLocalPlayer) {
// Makes crosshair visible
cameraComponent.cullingMask |= 1 << LayerMask.NameToLayer(“DontDrawCrosshair”);
}
When this happens, my crosshair as well as other user’s crosshair get visible as it is a clone of the original(mine). The game does not access the internet. It is LAN.
Any help appreciated.
Thanks!
- Add a layer called “Dont Show” by going to layers(top right) → edit layers
- Next to the area where the name of the object is written, there is a drop down called layer. In that select the layer you just made
- Got to your camera component in your camera gameobject. In the Culling Mask, select the layer you just added. This will remove that object from play mode.
- Make a C# script and attach it to the gameobject. In this, type:
using UnityEngine.Networking;
public class NAME OF SCRIPT : NetworkBehaviour {
void Update() {
if (isLocalPlayer) {
gameobject.layer = 1; // 1 is default, so it is visible
}
}
}