Search Unity

Chat Not Working Mac

Discussion in 'Scripting' started by JeremyGames, Jan 14, 2016.

  1. JeremyGames

    JeremyGames

    Joined:
    Jul 4, 2014
    Posts:
    21
    I'm in a group and we are making a fps and the chat script is working on windows but not mac,
    to activate the chat you press "t" and enter to send chat message. That works on windows but on mac when you press enter nothing happens and you cant close it... Thanks

    Code (CSharp):
    1. //NSdesignGames @ 2012
    2. //FPS Kit | Version 2.0 + Multiplayer
    3.  
    4. //Implementation of multiplayer chat inside rooms
    5.  
    6. using UnityEngine;
    7. using System.Collections;
    8. using System.Collections.Generic;
    9.  
    10. public class MultiplayerChat : Photon.MonoBehaviour{
    11.    
    12.     public static MultiplayerChat SP;
    13.    
    14.     public struct ChatData {
    15.         public string name { get; set; } //Name of sender
    16.         public string text { get; set; } //Message text
    17.         public Color color { get; set; } //Sender color
    18.         public float timer { get; set; } //Remove message after certain time
    19.        
    20.         public ChatData(string string1, string string2, Color color1, float timer1){
    21.                name = string1;
    22.             text = string2;
    23.             color = color1;
    24.             timer = timer1;
    25.         }
    26.  
    27.     }
    28.     public List<ChatData> messages = new List<ChatData>();
    29.  
    30.     private int chatHeight = (int)300;
    31.     private Vector2 scrollPos = Vector2.zero;
    32.     [HideInInspector]
    33.        public string chatInput = "";
    34.     [HideInInspector]
    35.     public bool isChatting;
    36.     public GUIStyle chatStyle;
    37.    
    38.     RoomMultiplayerMenu rmm;
    39.  
    40.     void Awake(){
    41.         SP = this;
    42.         rmm = gameObject.GetComponent<RoomMultiplayerMenu>();
    43.     }
    44.    
    45.     void Update(){
    46.         //Remove chat message after timer reach 0
    47.         for(int i = 0; i < messages.Count; i++){
    48.             ChatData tempData = messages[i];
    49.             tempData.timer -= Time.deltaTime;  
    50.             if(tempData.timer > 0){
    51.                 messages[i] = new ChatData(tempData.name, tempData.text, tempData.color, tempData.timer);
    52.             }else{
    53.                 messages.RemoveAt(i);  
    54.             }
    55.         }
    56.     }
    57.  
    58.     void OnGUI(){
    59.         GUILayout.BeginArea(new Rect(5, Screen.height - 35, Screen.width, 30));
    60.             //Chat input
    61.             if(isChatting){
    62.                 GUI.FocusControl("ChatField");
    63.                 GUI.SetNextControlName("ChatField");
    64.                 GUILayout.BeginHorizontal("box", GUILayout.Width(400));
    65.                     GUI.color = Color.red;
    66.                     GUILayout.Label("Say: ", chatStyle);
    67.                     GUILayout.Space(5);
    68.                     GUI.color = Color.white;
    69.                     chatInput = GUILayout.TextField(chatInput, chatStyle, GUILayout.Width(400));
    70.                 GUILayout.EndHorizontal();
    71.             }else{
    72.                 GUI.FocusControl("");
    73.             }
    74.         GUILayout.EndArea();
    75.        
    76.         //Open Chat
    77.           if (Event.current.type == EventType.keyDown && Event.current.keyCode == KeyCode.T && !isChatting){
    78.             isChatting = true;
    79.             StartCoroutine(ClearChat());
    80.         }
    81.         //Send Chat
    82.           if (Event.current.type == EventType.keyDown && Event.current.character == '\n'){  
    83.             isChatting = false;
    84.                SendChat(PhotonTargets.All);
    85.         }
    86.  
    87.         //Show scroll list of chat messages
    88.         GUILayout.BeginArea(new Rect(5, Screen.height - chatHeight-50, Screen.width, chatHeight+10));
    89.             scrollPos = GUILayout.BeginScrollView(scrollPos);{
    90.                 GUI.color = Color.white;
    91.                
    92.                 GUILayout.FlexibleSpace();
    93.                
    94.                 for (int i = 0; i < messages.Count; i++){
    95.                     GUILayout.BeginHorizontal("box", GUILayout.Width(10));
    96.                     GUI.color = messages[i].color;
    97.                     GUILayout.Label(messages[i].name, chatStyle);
    98.                     GUILayout.Space(5);
    99.                     GUI.color = Color.white;
    100.                     GUILayout.Label(messages[i].text, chatStyle);
    101.                     GUILayout.EndHorizontal();
    102.                 }
    103.             GUILayout.EndScrollView();}
    104.         GUILayout.EndArea();
    105.     }
    106.  
    107.     void SendChat(PhotonTargets target){
    108.         if (chatInput != ""){
    109.             string tempChat =" " +  chatInput;
    110.             photonView.RPC("SendChatMessage", target, tempChat, (string)PhotonNetwork.player.customProperties["TeamName"]);
    111.             chatInput = "";
    112.         }
    113.     }
    114.    
    115.     [RPC]
    116.     void SendChatMessage(string text, string teamName, PhotonMessageInfo info){
    117.         AddMessage("  " + info.sender + ": ", text, teamName);
    118.     }
    119.    
    120.     void AddMessage(string name, string text, string teamName){
    121.         Color tempColor = new Color();
    122.         if(teamName == rmm.team_1.teamName){
    123.             tempColor = rmm.team_1_Color;
    124.         }else{
    125.             tempColor = rmm.team_2_Color;
    126.         }
    127.        
    128.         SP.messages.Add(new ChatData(name, text, tempColor, 30));
    129.         //Message count limit
    130.         if (SP.messages.Count > 8)
    131.             SP.messages.RemoveAt(0);
    132.     }
    133.  
    134.     void OnLeftRoom(){
    135.         messages.Clear();
    136.         this.enabled = false;
    137.     }
    138.  
    139.     void OnJoinedRoom(){
    140.         this.enabled = true;
    141.     }
    142.     void OnCreatedRoom(){
    143.         this.enabled = true;
    144.     }
    145.  
    146.     IEnumerator ClearChat(){
    147.         yield return new WaitForSeconds(0.01f);
    148.         chatInput = "";
    149.     }
    150. }
    151.  
     
  2. LovelyPotatoe

    LovelyPotatoe

    Joined:
    Jan 14, 2016
    Posts:
    5
    So, just to be sure of what you're asking... Pressing [ENTER] doesn't send any messages and you cannot close the message box. Right?
     
  3. JeremyGames

    JeremyGames

    Joined:
    Jul 4, 2014
    Posts:
    21
    No enter sends the messages, and if theres no text entered then it closes when you press enter
     
    LovelyPotatoe likes this.
  4. LovelyPotatoe

    LovelyPotatoe

    Joined:
    Jan 14, 2016
    Posts:
    5
    Okay.
     
  5. LovelyPotatoe

    LovelyPotatoe

    Joined:
    Jan 14, 2016
    Posts:
    5
    By any chance have you tried restarting your browser, or possibly your computer?
    If this doesn't work, I'd also recommend trying to uninstall and reinstall the GameJolt Browser and see if it'd be a fix.
    There's a possibility this is a concatenation problem in your Mac or a mistake within the code as well.. And if it is, it's a teency bit beyond me at the moment of how to resolve the issue. If not it could also be a problem with specific definitions and conversions between your OSX operating system and whatever GameJolt runs, if different than Mac.
    But as for a fix... I don't know as of yet. I'll continue studying the code to see if I can find anything, but with my experience in the C language of programming, I am very rusty.
     
  6. LovelyPotatoe

    LovelyPotatoe

    Joined:
    Jan 14, 2016
    Posts:
    5
    Please keep me updated on anything that happens, so long as you have the time.
    And in the meantime I'm going to run this in Debugging mode in Visual Studio to see if anything comes up. Since I can't find anything within the code.
     
  7. JeremyGames

    JeremyGames

    Joined:
    Jul 4, 2014
    Posts:
    21
    ?!?! I'm asking a question about a unity game... Not gamejolt chat
     
  8. LovelyPotatoe

    LovelyPotatoe

    Joined:
    Jan 14, 2016
    Posts:
    5
    Oh! Well why didn't ya just say so..