Do something like this:
var timeSinceCollision = 999;
void Update() {
timeSinceCollision += Time.deltaTime;
if(timeSinceCollision < 0.5 && Input.GetMouseButtonDown(0)) {
// do something
}
}
void OnCollisionEnter() {
timeSinceCollision = 0;
}
The 0.5 makes it so that there's a bit of allowable tolerance for when the player collides with whatever and them being able to perform the action (no one is going to be able to press the button the same frame the collision occurs on: ideally that would be 1/60th of a second!).
Edit:
Also use GetMouseButtonDown
, which will only be true on the frame that the button is first pressed and false thereafter. It prevents the player from holding down the button, then bumping into something, and getting the effect despite doing things out of order.