- Home /
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?
Answer by ChrisTylr · Oct 02, 2013 at 05:45 PM
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 :)
Answer by DaveA · Oct 02, 2013 at 05:01 PM
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
Ok so i tried Input.Get$$anonymous$$ouseButton and that didn't make it better or worse, ive also changed Collision to Collider after an error message saying it had to be that.
As for setting bool states, what exactly would i be putting into a bool, and wouldn't that just add another condition to the if statement.
$$anonymous$$ake an OnTriggerStay function and move this code into it
Ive just changed my current function to OnTriggerStay and still nor better or worse
Your answer
