It’s my code and it works fine but always it shows that error,
what should I do ? should I really change it or it’s fine?
because the game works fine.
// pushing Escape= stop the game
//pushing Espace when the game is stopped will resume the game
public GameObject stopimage;
void Update () {
if (Input.GetKeyDown (KeyCode.Escape)&& !stopimage.active ) {
stopimage.SetActive (true);
Time.timeScale = 0;
}
else if (Input.GetKeyDown (KeyCode.Escape)&& stopimage.active) {
stopimage.SetActive (false);
Time.timeScale = 1;
}
}
GameObject.activeSelf
returns true if that gameobject is active, false otherwise. Note: It is possible for this to return true, but have the object behave as if it is inactive, due to a parent object being inactive. Documentation.
GameObject.activeInHierarchy
returns true if that object and all parent objects are active, false otherwise. Documentation.
Most of the time, you will want to use activeInHierarchy - it has the same behavior as the old .active
public GameObject stopimage;
void Update () {
if (Input.GetKeyDown (KeyCode.Escape)&& !stopimage.activeInHierarchy) {
stopimage.SetActive (true);
Time.timeScale = 0;
}
else if (Input.GetKeyDown (KeyCode.Escape)&& stopimage.activeInHierarchy) {
stopimage.SetActive (false);
Time.timeScale = 1;
}
}