[UNET] Method called on client but not on host player
Hello! So I'm currently working on a multiplayer game using the network manager, and it's basically a game where you have to keep your laser aimed at other players to desactivate them. My laser is working perfectly, but the problem I have is that the clients can use it and desactivate other players, but the host can't use it, and I have no idea why since this is the very first time I do a multiplayer game.
So this is the laser function that's on the player prefab :
[Client]
void ActivateLaser ()
{
laserTimer += Time.deltaTime;
RaycastHit _hit;
if (Physics.Raycast (m_Camera.transform.position, m_Camera.transform.forward, out _hit, Mathf.Infinity))
{
if (_hit.collider.gameObject.tag == "Player")
{
string _hitName = _hit.collider.name;
if (GameManager.GetPlayer (_hitName).isActive)
{
laserHitTimer += Time.deltaTime;
m_PlayerManager.LaserHoldingScore (laserHitTimer);
if (laserHitTimer >= desactivationLaserTime)
{
LaserHit (_hitName);
laserHitTimer = 0.0f;
}
}
}
}
else
{
laserHitTimer = 0.0f;
}
}
void LaserHit (string _hitPlayerID)
{
PlayerManager _hitplayer = GameManager.GetPlayer (_hitPlayerID);
PlayerManager _hittingPlayer = GameManager.GetPlayer (this.name);
if (_hitplayer.isActive)
{
_hitplayer.Desactivate ();
_hittingPlayer.DesactivationScore ();
}
}
(I've obviously tried to remove the [Client] attribute but it didn't fix the problem). And this is the code used to get the player ID :
private static Dictionary <string, PlayerManager> players = new Dictionary <string, PlayerManager> ();
public static void RegisterPlayer (string _netID, PlayerManager _player)
{
string _playerID = "Player " + _netID;
players.Add (_playerID, _player);
_player.transform.name = _playerID;
}
public static PlayerManager GetPlayer (string _playerID)
{
return players [_playerID];
}
Thanks a lot for giving me some of your time! :)
Your answer
Follow this Question
Related Questions
SyncVars not updating on client 1 Answer
Network Transport Layer API does not work with iOS to PC???? 0 Answers
Unity 5 Unet Network Rigidbody Syncing - Client sinking through objects. 0 Answers
Is there any way to do automatic p2p matchmaking system via Unet? 0 Answers
[Hololens] Connecting using Unity's UNET doesn't work after the first time connecting 1 Answer