When keyboard 'H' is pressed i want the platformer (wall, roof, floor) become invisible when its visible and become visible when its invisible. Like giving the player ability to control visibility of certain wall so he can pass through it.
This is what i do so far but the wall become blink when i press 'H'. Sometimes the wall become invisible but sometimes it just blink.
public class HideWall : MonoBehaviour {
public SpriteRenderer wall;
public Collider2D wallCollider;
public Effector2D wallEffector;
private bool visible;
// Use this for initialization
void Start () {
wall = GetComponent<SpriteRenderer> ();
wallCollider = GetComponent<Collider2D> ();
wallEffector = GetComponent<Effector2D> ();
visible = true;
}
// Update is called once per frame
void Update () {
if (Input.GetKey(KeyCode.H)) {
wall.enabled = !wall.enabled;
wallCollider.enabled = !wallCollider.enabled;
wallEffector.enabled = !wallEffector.enabled;
}
}
}