在游戏运行时,在game面板点击关闭按钮,game面板中的物体没有被关闭,而scene面板的物体已被关闭,请教大神这是为什么以及该如何解决。。
下面是我的代码:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PwdCheck : MonoBehaviour
{
//关闭按钮
private GameObject closeBtn;
//判断密码输入
private UIInput passwordInput;
//确定按钮
private GameObject sureBtn;
void Start ()
{
closeBtn = gameObject.transform.Find ("closeBtn").gameObject;
UIEventListener.Get (closeBtn).onClick += new UIEventListener.VoidDelegate (CloseBtnHandler);
sureBtn = gameObject.transform.Find ("sureBtn").gameObject;
UIEventListener.Get (sureBtn).onClick += new UIEventListener.VoidDelegate (SureBtnHandler);
}
///
/// 关闭按钮点击后的处理函数
///
void CloseBtnHandler(GameObject go)
{
Debug.Log ("关闭按钮点击");
Destroy (this.gameObject);
}
///
/// 确定按钮处理函数
///
void SureBtnHandler(GameObject go)
{
bool isPasswordOk = CheckPassword (passwordInput.value);
Debug.Log ("开始检测密码!");
if (isPasswordOk)
{
Destroy (this.gameObject);
Debug.Log ("密码已输入!");
}
else
{
transform.Find ("error Label").gameObject.SetActive(true);
}
}
///
/// 判断密码是否正确
///
bool CheckPassword(string currentPassword)
{
currentPassword="JustFraud";
if (passwordInput.value == currentPassword)
{
return true;
}
else
return false;
}
}