my script not work
always my program Unity freezes or turn off window game
i use two scripts Please Help me edit script
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class ChatBoxFunctions : MonoBehaviour
{
[SerializeField]
ContentSizeFitter contentSizeFitter;
[SerializeField]
Text showHideButtonText;
[SerializeField]
Transform messageParentPanel;
[SerializeField]
GameObject newMessagePrefab;
bool isChatShowing = false;
string message = "";
void Start()
{
ToggleChat();
}
public void ToggleChat()
{
isChatShowing = !isChatShowing;
if (isChatShowing)
{
contentSizeFitter.verticalFit = ContentSizeFitter.FitMode.PreferredSize;
showHideButtonText.text = "Hide Chat";
}
else
{
contentSizeFitter.verticalFit = ContentSizeFitter.FitMode.MinSize;
showHideButtonText.text = "Show Chat";
}
}
public void SetMessage(string message)
{
this.message = message;
}
public void ShowMessage()
{
if (message != "")
{
GameObject clone = (GameObject)Instantiate(newMessagePrefab);
clone.transform.SetParent(messageParentPanel);
clone.transform.SetSiblingIndex(messageParentPanel.childCount - 2);
clone.GetComponent<MessageFunctions>().ShowMessage(message);
}
}
}
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class MessageFunctions : MonoBehaviour {
public static string Player;
public float Collor;
void Update()
{
Player = database.user;
}
public void White()
{
Collor = 1;
}
public void Red()
{
Collor = 2;
}
public void Green()
{
Collor = 3;
}
public void Yelow()
{
Collor = 4;
}
public void Blue()
{
Collor = 5;
}
[SerializeField] Text text;
public void ShowMessage(string message) {
if (Collor == 1)
{
text.color = Color.white;
text.text = Player + ":" + message ;
}
if (Collor == 2)
{
text.color = Color.red;
text.text = Player + ":" + message;
}
if (Collor == 3)
{
text.color = Color.green;
text.text = Player + ":" + message;
}
if (Collor == 4)
{
text.color = Color.yellow;
text.text = Player + ":" + message;
}
if (Collor == 5)
{
text.color = Color.blue;
text.text = Player + ":" + message;
}
}
public void HideMessage() {
Destroy(gameObject);
}
}