C# bug with a class boolean ?

I have a gamemanager class in C# :

public class GameManager : MonoBehaviour
{
   ....
   ....
   bool perdu = false;

public void aPerdu()
    {
        perdu = true;
        Debug.Log("aPerdu "+perdu);
    }
 void Update()
{
   Debug.Log("Update:" + perdu);

)

I call the function aPerdu() to set the boolean to true. Nowhere else in the code the boolean is set to a value (true or false).

In my trace i have a “aPerdu true” and in Update it keep stating that perdu is false. i do not understantd how can my aPerdu change scope is limited to the function.

This is something i done thousands of times in Java, how can c#/unity act differently? What am i doing wrong?

PS : Sorry for the missing closing brackets but alt gr + the key next to backspace (fr keyboard) generate a enter code here instead of closing bracket

the answer to your problem is very simple. nearly all of your methods are inherited by MonoBehaviour. Start(), Update() a.s.o. will be called automatically in unity. your method aPerdu() doesn’t exist in MonoBehaviour, so you have to call it in one of the other methods.

For Example:

void Update()

{

aPerdu();

}