Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Network bullet player display text

Discussion in 'Multiplayer' started by mezdari77580, Dec 21, 2018.

  1. mezdari77580

    mezdari77580

    Joined:
    Nov 7, 2018
    Posts:
    4
    Hello all,

    i am doing a simple multiplayer game, the game it is a shooter game where each player can throw
    chopped to other player, when you touch one player, you must have a UI text which display a message which inform that you have touch other player.

    But the player wich launch the doesn't have the message,
    i don't know why ?


    So i have :

    Code (CSharp):
    1.  
    2. public class Charact : NetworkBehaviour {
    3.    [SyncVar]
    4.     public bool touche= false;
    5.    [SyncVar]
    6.     public int health;
    7.  
    8.     private void OnTriggerEnter(Collider other)
    9.     {
    10.  
    11.         if (other.gameObject.name == "weapon(Clone)")
    12.         {
    13.          
    14.             if (other.GetComponent<Bullet>().isMoving)
    15.             {
    16.              
    17.                 Destroy(other.gameObject);
    18.              
    19.                 health--;
    20.  
    21.                 NetworkInstanceId id = other.gameObject.GetComponent<Bullet>().playerWichLaunch.GetComponent<NetworkIdentity>().netId;
    22.                 Cmd_affichageUiTouche(id);
    23.                
    24.  
    25.             }
    26.         }  
    27.     }
    28.  
    29.  [Command]
    30.     public void Cmd_affichageUiTouche(NetworkInstanceId id)
    31.     {
    32.         Rpc_affichageUiTouche(id);
    33.     }
    34.  
    35.     [ClientRpc]
    36.     void Rpc_affichageUiTouche(NetworkInstanceId id)
    37.     {
    38.         if (this.GetComponent<NetworkIdentity>().netId.Equals(id))
    39.         {
    40.                 this.touche = true;
    41.            
    42.         }
    43.     }
    44. }
    45.  
    46.  
    thx for your responses
     
  2. mezdari77580

    mezdari77580

    Joined:
    Nov 7, 2018
    Posts:
    4
    the bullet script have a charact wich launch him in attribute :
    Code (CSharp):
    1. public class Bullet : NetworkBehaviour {
    2.  
    3. public GameObject playerWichLaunch;
    4.  
    5. public Bullet(GameObject playerWichLaunch){
    6. this.playerWichLaunch = playerWichLaunch;
    7. }
    and when player launch a chopped this code is execute :
    Code (CSharp):
    1.   Cmd_lancerDeHache(this.gameObject);
    2.  
    3. [Command]
    4.     public void Cmd_lancerDeHache(GameObject player)
    5.     {
    6.         Bullet bul = new Bullet(this.transform.GetChild(1).transform.forward,
    7.                   hache, player, transform.position + (transform.forward * 2) + (transform.up * 1.5f),
    8.                   this.transform.rotation, transform.parent);
    9.  
    10.         NetworkServer.Spawn(bul.Instantiate());
    11.        // Rpc_lancerDeHache(bulObject);
    12.     }
     
  3. mezdari77580

    mezdari77580

    Joined:
    Nov 7, 2018
    Posts:
    4
    when my varibale value "touche" is true, so the text will display, but this variable is never at true