Search Unity

  1. Are you interested in providing feedback directly to Unity teams? Sign up to become a member of Unity Pulse, our new product feedback and research community.
    Dismiss Notice

[Urgent!]Chat with players in the same area only.

Discussion in 'Multiplayer' started by unitygirl, Jun 17, 2010.

  1. unitygirl

    unitygirl

    Joined:
    May 25, 2010
    Posts:
    38
    Hi! I'm trying to make the chat window system
    where network players in different area within the same scene cannot talk to each other.

    For more details about the code, click the link following:
    http://forum.unity3d.com/viewtopic.php?p=328247#328247

    I've been suggested the solution from the link above, who told me to make string varaible "currentLevel", and call RPC function with this variable.

    But it did not told me how to assign the value of this string, so I wrote the code below:

    Code (csharp):
    1.  
    2. var ChatArea: ChatWindow_test;
    3. var chatWinObj: GameObject;
    4.  
    5. function Start()
    6. {
    7.     chatWinObj = GameObject.Find("ChatWindow");
    8.     ChatArea = chatWinObj.GetComponent("ChatWindow_test");
    9. }
    10.  
    11. function OnTriggerEnter (other : Collider)
    12. {  
    13.     switch(gameObject.name)
    14.     {
    15.         case "levelTrigger_Lobby":
    16.         Debug.Log("Trigger Entered: Lobby");
    17.         ChatArea.currentLevel = "Lobby";
    18.         break;
    19.        
    20.         case "levelTrigger_Lec1":
    21.         Debug.Log("Trigger Entered: Lobby");
    22.         ChatArea.currentLevel = "Lec1";
    23.         break;
    24.        
    25.         case "levelTrigger_Lec2":
    26.         Debug.Log("Trigger Entered: Lobby");
    27.         ChatArea.currentLevel = "Lec2";
    28.         break;
    29.     }
    30. }
    31.  
    This code is attached to the floor of each area, and if any players touch the floor of the area, it changes the value of "currentLevel". but problem is that it changes the value of currentLevel of other players in the network resulting the situation where they can still talk to each other, even tho they are all in different area.

    In other words, I'm not sure how to let network players to have their own "currentLevel" variable.

    Could anyone help?!
     
  2. MikeHergaarden

    MikeHergaarden

    Joined:
    Mar 9, 2008
    Posts:
    1,019
    Code (csharp):
    1.  
    2. function OnTriggerEnter (other : Collider)
    3. {
    4.    switch(gameObject.name)
    5.    {
    You didnt check if it's just the LOCAL player that enters the trigger. at the moment it runs for all players.

    Add something like

    Code (csharp):
    1.  
    2. function OnTriggerEnter (other : Collider)
    3. {
    4. PlayerScript myPlayer = other.gameObject.GetComponent(Playerscript);
    5.  
    6. if(myPlayer.isLocalPlayer){
    7.    switch(gameObject.name)
    8.    {
     
  3. unitygirl

    unitygirl

    Joined:
    May 25, 2010
    Posts:
    38
    Thanks for quick reply! I'm glad to have reply from someone from M2H tutorial :)

    so I kinda understand that you obtain this 'Playerscript' from the gameobject which has collider that entered the trigger,

    and then refer to this 'isLocalPlayer' variable to identify whether it was my player or it was other player...

    And I indeed have referred most of the points in M2H Tutorial, but I didn't quite use the Playerscript.

    So Could you explain what this Playerscript do?

    Plus, although I didn't really tried this isLocalPlayer function yet so I cannot be so sure... but wouldn't it be same even if I identify whose collider is was, because everybody(not only me - if someone else goes into different area they wouldn't be able to talk with me as well) meant to change the 'currentLevel' variable of their own but not to change others... but in this case we didn't do anything on this variable to be assigned on each network player so wouldn't it still change others 'currentLevel' varialbe?
    (Am I saying the words right?)

    Of course I could just ask for help and wait, but my purpose is to understand these... so I'd like to listen to some explanation if it doesn't bother you much :)
     
  4. MikeHergaarden

    MikeHergaarden

    Joined:
    Mar 9, 2008
    Posts:
    1,019
    Well the Playerscript is just an example, you probably don't have something like it. I just meant to say that somehow you need to check the colliding object to see if its the localplayer, you could even use a tag or gameObject naming for that.
     
unityunity