Skip to main content
Fix key method to use.
Source Link
Droppy
  • 214
  • 1
  • 6

Only make the change if it's not already in the state you want:

void Update () {
    bool wantToHide = Input.GetKeyGetKeyDown(KeyCode.H);
    bool alreadyHidden = !wall.enabled;
    if (wantToHide != alreadyHidden) {
        wall.enabled = !wantToHide;
        wallCollider.enabled = !wantToHide;
        wallEffector.enabled = !wantToHide;
    }
}

Also processing input within non-player-oriented script is kinda crappy; so create a player controller object and attach it to scene and get that to call the above script when the state changes.

Only make the change if it's not already in the state you want:

void Update () {
    bool wantToHide = Input.GetKey(KeyCode.H);
    bool alreadyHidden = !wall.enabled;
    if (wantToHide != alreadyHidden) {
        wall.enabled = !wantToHide;
        wallCollider.enabled = !wantToHide;
        wallEffector.enabled = !wantToHide;
    }
}

Also processing input within non-player-oriented script is kinda crappy; so create a player controller object and attach it to scene and get that to call the above script when the state changes.

Only make the change if it's not already in the state you want:

void Update () {
    bool wantToHide = Input.GetKeyDown(KeyCode.H);
    bool alreadyHidden = !wall.enabled;
    if (wantToHide != alreadyHidden) {
        wall.enabled = !wantToHide;
        wallCollider.enabled = !wantToHide;
        wallEffector.enabled = !wantToHide;
    }
}

Also processing input within non-player-oriented script is kinda crappy; so create a player controller object and attach it to scene and get that to call the above script when the state changes.

Source Link
Droppy
  • 214
  • 1
  • 6

Only make the change if it's not already in the state you want:

void Update () {
    bool wantToHide = Input.GetKey(KeyCode.H);
    bool alreadyHidden = !wall.enabled;
    if (wantToHide != alreadyHidden) {
        wall.enabled = !wantToHide;
        wallCollider.enabled = !wantToHide;
        wallEffector.enabled = !wantToHide;
    }
}

Also processing input within non-player-oriented script is kinda crappy; so create a player controller object and attach it to scene and get that to call the above script when the state changes.