[英]Chat background in unity3d
我想問個問題。 我怎樣才能使像這樣的鏈接聊天背景?
使用自動文本(文本每次會自動一一鍵入一個文字)。
問題是,我已經完成了與上圖類似的聊天背景,但是使用透明背景,當我嘗試在透明背景中填充文本時,文本沒有顯示。
這是透明背景上的圖像:
這是我一直在使用的代碼(自動文本):
using UnityEngine;
using System.Collections;
public class AutoText : MonoBehaviour
{
public float letterPause = 0.5f; // Define and set the pause for each letters
public AudioClip sound = null; // For the sound
public GUISkin customLabel = null; // For the label
public static string message = "Help...! Help...!" + "\n" + "Somebody...! Please Help Me...!"; // The message
private void Start()
{
StartCoroutine(TypedText());
}
private void OnGUI()
{
GUI.Label(new Rect((Screen.width / 2) - 250, (Screen.height / 2) - 200, 500, 500), message, customLabel.customStyles[0]);
}
IEnumerator TypedText()
{
// Loop through the message
foreach (char letter in message.ToCharArray())
{
// Set the gui text to be same with message
guiText.text += letter;
// If sound available
if (sound)
{
// Play it on each words
audio.PlayOneShot(sound);
// Go back to the if statement
yield return 0;
}
// Each letters will be shown for how many seconds delay
yield return new WaitForSeconds(letterPause);
}
}
}
對於文本本身,我在統一編輯器中創建一個gui文本和gui外觀並將腳本放在上面,如下圖所示:
而且,當我嘗試將聊天背景設置為不透明時,該文本位於聊天背景后面(因此該文本未顯示)
先生,非常感謝您回答這個問題並感興趣。
您不能只是嘗試在Text :)后面繪制紋理嗎?
首先在腳本中將紋理添加為變量
public Texture2D Background;
然后將您的OnGUI更改為
private void OnGUI()
{
GUI.DrawTexture(new Rect((Screen.width / 2) - 250, (Screen.height / 2) - 200, 500, 500), Background);
GUI.Label(new Rect((Screen.width / 2) - 250, (Screen.height / 2) - 200, 500, 500), message, customLabel.customStyles[0]);
}
不要忘了先在編輯器中分配背景紋理。 還要放在導入的紋理上。 將透明度設置為來自Alpha通道。
如果沒有測試,我可以保證它會工作:-)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.