First of all I want to thank you guys. Reading the answers of the other questions, made a lot of things clear to me.
This is my problem:
I’m working on a 2D asteroid like game. There is a spaceship and it has a package connected (i’m using SringJoint2D to that).
When the player press “space” the package is disconnected:
if(Input.GetKeyDown(KeyCode.Space))
{
//SpringJoint2D
sj2d.enabled=false;
//this is just a bool variable to "record" if it's free
estaSolta=true;
}
There are two kinds of triggers that the package can collide. The right one (the package destiny) and the wrong one (the rest).
When the package collides, it’s supposed to show up a GUI menu. And this is the code i’m using to that:
void OnTriggerEnter2D(Collider2D col)
{
//if it collides with the right trigger
if(col.gameObject.tag=="destino")
{
if (estaSolta == true)
{
Time.timeScale=0f;
menuVitoria = true;
}
}
//if it collides with the wrong trigger
else
{
if (estaSolta == true)
{
Instantiate(explosao,transform.position, new Quaternion());
gameObject.SetActive(false);
menuDerrota=true;
Time.timeScale=0f;
}
}
}
void OnGUI()
{
//if it collides with the wrong trigger
if(menuDerrota)
{
//this is just an if to verify if the player selected Portuguese in the language menu
if(PlayerPrefs.GetInt("lingua")==1?true:false)
{
GUI.BeginGroup(new Rect(Screen.width/10, Screen.height/10, 400, 300));
GUI.Box(new Rect(0, 0, 400, 400), "Perdeu!!");
Screen.showCursor=true;
GUI.EndGroup();
}
//if it is in English
else
{
GUI.BeginGroup(new Rect(Screen.width/10, Screen.height/10, 400, 250));
GUI.Box(new Rect(0, 0, 400, 400), "You've lost");
Screen.showCursor=true;
GUI.EndGroup();
}
}
//if it collides with the right trigger
if(menuVitoria)
{
if(PlayerPrefs.GetInt("lingua")==1?true:false)
{
GUI.BeginGroup(new Rect(Screen.width/10, Screen.height/10, 400, 300));
GUI.Box(new Rect(0, 0, 400, 400),
"Meus parabens, voce conseseguiu fazer a entrega no prazo");
Screen.showCursor=true;
GUI.EndGroup();
}
else
{
GUI.BeginGroup(new Rect(Screen.width/10, Screen.height/10, 400, 250));
GUI.Box(new Rect(0, 0, 400, 400),
"Congratulations, you delivered on time");
Screen.showCursor=true;
GUI.EndGroup();
}
}
}
What is happening:
When the package collides with the right trigger, the game freezes and the GUI menu appears but when the package collides with any other thing the game freezes, the bool variable menuDerrota becomes true but the GUI menu doesn’t appear
Thanks for your comments. I was not thinking to have more than two languages. But now, If I need to change to that, your comment will help me a lot.
– Ricardo_Alves