- Home /
Shield for player in multiplayer fps malfunctioning
ok, so I have a gameobject on my player prefab i have to disable to disable my shield. It gets activated at start and disabled if you move or shoot. anything I try is resulting in undesirable behaviour. If a player shoots or moves, every player's shields get disabled, but that is not synced ,i.e, I have to shoot from a players and it will disable shields on only that client. For it to be shown on other clients i will have to move and shoot in that client too. I want it to disable only the local player's shield but it is not working. code :
using System.Collections;
using UnityEngine;
using UnityEngine.Networking;
public class PlayerShield : NetworkBehaviour {
public GameObject shield;
private float Duration = 20.0f;
public static bool active = false;
private bool doOnce = true;
private void Start()
{
if (!active)
{
Disabler();
}
}
private void Update()
{
if (doOnce)
{
if (active)
{
StopCoroutine(DisableCollider());
Duration = 0.0f;
Disabler();
doOnce = false;
}
}
}
[Client]
public void Shield(float _time)
{
Duration = _time;
Disabler();
}
void Disabler()
{
StartCoroutine(DisableCollider());
}
IEnumerator DisableCollider()
{
yield return new WaitForSeconds(Duration);
shield.SetActive(false);
}
}
Because your code didnt check other player shield is belong the them.
Check if player belong this Client or This Player, then active shield otherwise return null.
Your answer
![](https://koobas.hobune.stream/wayback/20220612163355im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
RaycastAll Detect if nothing hit 1 Answer
How to Debug in a standalone build? 4 Answers
Need help for ignoring FPS layers 0 Answers