ontriggerenter and setting bool to true

i have a jetpack script which i want to work the following way: you pick up the jetpack from the ground and then when its on your back you’re able to fly with it… And that sort of works, but only if i hold down the fly key as i enter the jetpack object, if i pick it up and try to press the fly key after, it doesnt work :confused: i can set the bool to true in the inspector, after i picked up the object and im able to fly fine. Also i cant fly that way before ive picked up the jetpack, so it works 80% of the way… i have a suspicion that i might have to use a coroutine, or put something in update, idk

my code is as follows:

public class JetPack : MonoBehaviour {

	public bool renderEnabled = false;


	void Awake()
	{
		GameObject.FindGameObjectWithTag ("JetPack").renderer.enabled = false;
	}


	void OnTriggerEnter2D(Collider2D other)
	{
		if (other.gameObject.tag == "Player") 
		{
			enableRender();
			Destroy (gameObject);
		}
	}

	public void enableRender()
	{
		renderEnabled = true;
		GameObject.FindGameObjectWithTag("JetPack").renderer.enabled = true;

	}
}

and in the player class:

if(jetPack.renderEnabled == true)
		{
			if(controller.moving.y > 0)
			{
				if(absVelY < MaxVelocity.y)
				{
					forceY = jetSpeed * controller.moving.y;
				}
			}
		}

void OnTriggerEnter2D(Collider2D other)
	{
		if(other.gameObject.tag == "jetpackitem")
		{
			jetPack.renderEnabled = true;
		}
	}

Nvm - i simply put the code from the jetpack script into the player script, removed the jetpack script from the jetpack on the ground and now it works :slight_smile:
mods can close or delete this question