Can't access nested if...

Basically what i’m trying to do is create a collision volume, and when the player enters that volume a message is displayed ‘press right mouse button to use weapon’ and if they press the right mouse button they can use the weapon.

But before i write the code for the weapon im testing to see if im getting in the nested if, and im not…

I want the message to display, regardless of any buttons pressed, so i dont want to condition the if statement with a (collision + a button press)…

This is my code:-

function OnTriggerEnter(collision:Collision)
{

	if (collision != 'Player')
	{
		displayMessage = true;
		yield WaitForSeconds (displayTime);
		displayMessage = false;
		//Debug.Log("This is triggered");
		
		if (Input.GetMouseButtonDown(1))
		{
			Debug.Log('This will tell me if i get inside the nested if');
		}
	}

EDIT:

Ok so i moved :

if (Input.GetMouseButton(1))
{
    testPlayerCollision = true;
    Debug.Log('This will tell me if i get inside the nested if');
}

outside of the first if statement, so i now have two if statements in the function, and they both work, but the second if waits until the first if is complete before it will work.

I assume this is down to the ‘yield WaitForSeconds (displayTime);’ but is there a way to still have my message showing for x amount of time and still triggering the second function?

Because both events would have to happen at the same time. Use Input.GetMouseButton instead, as a first cut. You may need to resort to setting some boolean state variables though. Or look for the mouse down in OnTriggerStay

never mind, solved it…

i just switched the if statements round so the message was under the mouse click, works fine now.

Thanks for trying to help :slight_smile: