Hello.
I have a little problem, ive got a script, lets say Script_1, in which there is a while loop, that is running as long as the player is alive. I am accessing bool variable for the while loop from another script, Script_2.
In Script_2, in which the variable is declared, i need to change the value of the variable on impact, i.e. the player dies on impact.
As i have found on other threads, i can access the variable, if it is public static bool variable.
And in deed, i accessed this variable in the Script_1 like this:
//Script_2
public static bool alive = true;
//Script_1
bool playeralive = Script_2.alive;
The problem is, that when there is an actual impact, and i have in Script_2:
void OnTriggerEnter(Collider other)
{
if (other.tag == "Asteroid")
alive = false;
}
The variable has not changed, because if it did, the game would end itself.
This is the loop in Script_1:
bool playeralive = Script_2.alive;
while (playeralive)
{
for (int i = 0; i < hazardcount; i++)
{
Vector3 spawnpos = new Vector3(sth,sth,sth);
Quaternion spawnrot = Quaternion.identity;
Instantiate(hazard, spawnpos, spawnrot);
}
hazardcount = hazardcount + 5;
}
Application.Quit();
I am very sorry, if this is completely wrong, just started a few days ago. I would appreciate any advice, thanks.