I have a GameObject witch displays a fast login like interface and once you identify other script calls a function on the first to destroy it. This is the code:
string txtLogin = "Login";
string txtPass = "Pass";
void OnGUI(){
txtLogin = GUI.TextField (new Rect (25, 50, 100, 25), txtLogin);
txtPass = GUI.TextField (new Rect (25, 75, 100, 25), txtPass);
if (GUI.Button (new Rect (10,10,70,30), "Login")) {
print(txtLogin+" - "+txtPass);
Business.User user = new Business.User();
user.Pass=txtPass;
user.Login=txtLogin;
Server.loginUser(user);
}
}
public void loginError(){
txtLogin = "Login ERROR";
}
public void loginSuccess(){
GameObject clientObj = GameObject.Find("Client");
Client clientComp = clientObj.GetComponent("Client") as Client;
clientComp.init();
Debug.Log("BLASBLS");
Destroy(gameObject);
Destroy(this);
Debug.Log("BLASBLS");
}
But although the gameObject seems to be destroyed, its gui elements still shows on screen. What am I doing wrong???
After the "Destroy(gameObject);" I`m doing "Destroy(this);" to destroy the only script the object has. What other script should I destroy????
– TieSKeyYou should destroy all scripts related to the object. Scripts that extends MonoBehaviour -can- be attached to an gameobject, however it doesn't mean that they will stop executing if the gameobject is destroyed; and it doesn't mean they need to be attached to execute something.
– anon93868717I still dont get it. I have only 1 script attached to the gameobject. Extending "MonoBehaviour" attaches some script by default? Calling "GUI.<something> attaches a script? If so plz guide me on how to destroy them.
– TieSKey