My script for a "shield" function goes on/off constantly when it's supposed to be on

Couldn’t think of a great title for this question, heh. I did see a similar question before posting this, but didn’t really get an answer out of it: Here

The problem I’m having is this… I want to hold a button and have a few things happen. Mostly a boolean should become false and a few things should become true as you can see below. The problem is, apparently with the way I’m telling it to “stop” it all just does’t work properly. Everything flickers true/false constantly while holding the button instead of it all staying “on” basically. Apologies if none of this makes sense, but I can’t think of a better way to put it.
If someone could help me out a bit with this I would really appreciate it. I think it has something to do with the way I’m telling it all to stop.

Thanks. :slight_smile:

Here’s the part of the script that tells it to do this and which isn’t working.

if(CanGetHurt == true && Input.GetButton("Shield"))
  {
    CanGetHurt = false;
    ShieldParticles.enableEmission = true;
	ShieldCollider.gameObject.active = true;
	PlayerCollider.gameObject.collider.enabled = false;
  } else
  {
    ShieldParticles.enableEmission = false;
	ShieldCollider.gameObject.active = false;
	CanGetHurt = true;
	PlayerCollider.gameObject.collider.enabled = true;
  }

Would this help:

    if ( Input.GetButtonDown("Shield") )
    {
        CanGetHurt = false;
    	ShieldParticles.enableEmission = true;
    	ShieldCollider.gameObject.active = true;
    	PlayerCollider.gameObject.collider.enabled = false;
    }
    if ( Input.GetButtonUp("Shield") )
    {
    	ShieldParticles.enableEmission = false;
    	ShieldCollider.gameObject.active = false;
    	CanGetHurt = true;
    	PlayerCollider.gameObject.collider.enabled = true;
    }