Unity3D鼠标点击没有反应
如题,没有反应,原本是MSGcontroller(“1111”);改成控制台就有反应using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class MSGcontroller : MonoBehaviour
{
public Text txt;
public static string currentmsg;
public static void AddMsg(string msg)
{
currentmsg = currentmsg +"\n"+ msg;
}
IEnumerator msgUpdate()
{
while (true)
{
txt.text = currentmsg;
yield return new waitForSeconds(0, 0.5f);
}
}
void onEnable()
{
StartCoroutine(msgUpdate());
}
void onDisable()
{
StopCoroutine(msgUpdate());
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class test : MonoBehaviour
{
void Update()
{
if (Input.GetMouseButton(0))
{
MSGcontroller.AddMsg("11111");
}
}
}
这是两个脚本
test.cs中要获取到MSGcontroller,或者用单例吧
页:
[1]