点击翻页,NPC对话(不好看版,没调)
调用txt文件
a第一行
@
b第2行
@
C第3行
@
D第4行
//显示不出中文
using UnityEngine;
using System.Collections;
public class txt: MonoBehaviour {
bool BeNotOnGUI=false;
int i;
public TextAsset AAA;
public GUISkin gui;
int IntLength;
int index=0;
bool closer;
Rect windowRect =new Rect(50,400,500,100);
// Use this for initialization
void Start () {
closer=false;
}
// Update is called once per frame
void Update () {
if(BeNotOnGUI)
{
i++;
print(i);
}
}
void OnGUI ()
{
GUI.skin=gui;
//用来当物体的GUI
if(GUI.Button(new Rect(200,300,400,200),"???爱上"))
{
closer=!closer;
if(closer)
{
index=0;
}
}
//判断鼠标点击的是否是GUI
if (Event.current.type == EventType.MouseDown)
{
BeNotOnGUI=true;
}
else if (Event.current.type == EventType.MouseUp)
{
BeNotOnGUI=false;
}
if(!closer)
{
windowRect = GUILayout.Window (0, windowRect, DoMyWindow, "My Window");
}
}
void DoMyWindow (int windowID)
{
string JieShou=AAA.ToString();
string []jarrayJieShou=JieShou.Split (‘@’);
int IntLength=jarrayJieShou.Length;
GUILayout.Space (20);
GUILayout.BeginHorizontal ();
GUILayout.Space (20);
GUILayout.Label (jarrayJieShou[index]);
GUILayout.EndHorizontal ();
GUILayout.BeginArea (new Rect(200,90,50,24));
if (GUILayout.Button ("Next",GUILayout.Width(50)))
{
if(index<IntLength-1)
{
index++;
}else
{
closer=true;
index=0;
}
}
GUILayout.EndArea ();
GUI.DragWindow (new Rect (0,0,10000,10000));
}
}
用字符串翻页
using UnityEngine;
using System.Collections;
public class xunlu: MonoBehaviour {
bool BeNotOnGUI=false;
int i;
public GUISkin gui;
int IntLength;
int index=0;
string []body=new string[]{"现在开始上课","第一节","好好学习","天天向上"};
bool closer;
Rect windowRect =new Rect(Screen.width/2,Screen.height /2,500,100);
// Use this for initialization
void Start () {
closer=true;
}
// Update is called once per frame
void Update () {
if(BeNotOnGUI)
{
i++;
print(i);
}
}
void OnGUI ()
{
GUI.skin=gui;
//用来当物体的GUI
if(GUI.Button(new Rect(200,300,400,200),"点击帮助"))
{
closer=!closer;
if(closer)
{
index=0;
}
}
//判断鼠标点击的是否是GUI
if (Event.current.type == EventType.MouseDown)
{
BeNotOnGUI=true;
}
else if (Event.current.type == EventType.MouseUp)
{
BeNotOnGUI=false;
}
if(!closer)
{
windowRect = GUILayout.Window (0, windowRect, DoMyWindow, "My Window");
}
}
void DoMyWindow (int windowID)
{
int IntLength=body.Length;
GUILayout.Space (20);
GUILayout.BeginHorizontal ();
GUILayout.Space (20);
GUILayout.Label (body[index]);
GUILayout.EndHorizontal ();
GUILayout.BeginArea (new Rect(200,76,50,24));
if (GUILayout.Button ("Next",GUILayout.Width(50)))
{
if(index<IntLength-1)
{
index++;
}else
{
closer=true;
index=0;
}
}
GUILayout.EndArea ();
GUI.DragWindow (new Rect (0,0,10000,10000));
}
}