Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- using System.Collections.Generic;
- public class ChatManager : MonoBehaviour
- {
- public List<ChatMessage> chatMessages = new List<ChatMessage>();
- public bool IsWriting;
- public string currentText;
- void Update()
- {
- if (Input.GetKeyDown(KeyCode.T))
- {
- IsWriting = true;
- currentText = "";
- }
- }
- void OnGUI()
- {
- if (IsWriting || chatMessages.Count > 0)
- {
- GUILayout.BeginArea(new Rect(10, Screen.height / 2 - 150, 200, 300), "", "box");
- foreach (ChatMessage mes in chatMessages)
- {
- GUILayout.BeginHorizontal();
- GUILayout.Label(mes.owner.PlayerName);
- GUILayout.Label(mes.message);
- GUILayout.EndHorizontal();
- }
- GUILayout.EndArea();
- }
- if (IsWriting)
- {
- currentText = GUI.TextField(new Rect(10, Screen.height / 2 + 130, 200, 30), currentText);
- if (Event.current.Equals (Event.KeyboardEvent ("return")))
- {
- IsWriting = false;
- networkView.RPC("GetMessage", RPCMode.All, Network.player, currentText);
- }
- }
- }
- [RPC]
- void GetMessage(NetworkPlayer player, string Message)
- {
- ChatMessage tempmessage = new ChatMessage();
- tempmessage.owner = MultiplayerManager.GetMPPlayer(player);
- tempmessage.message = Message;
- chatMessages.Add(tempmessage);
- StartCoroutine(RemoveChatMessage(tempmessage));
- }
- IEnumerator RemoveChatMessage(ChatMessage mes)
- {
- yield return new WaitForSeconds(7.5f);
- chatMessages.Remove(mes);
- }
- }
- [System.Serializable]
- public class ChatMessage
- {
- public MPPlayer owner;
- public ChatForPeople forPeople;
- public string message;
- }
- public enum ChatForPeople
- {
- Everybody,
- Team,
- SpecificPerson
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement