Hello everyone,
I would like to know if there’s a way to force the player to press a determinate key by script, for example, i want the player to automatically press “c” when he is dead, just want to know is this is possible.
Thanks in advance.
Hello everyone,
I would like to know if there’s a way to force the player to press a determinate key by script, for example, i want the player to automatically press “c” when he is dead, just want to know is this is possible.
Thanks in advance.
I’m a little confused by the phrasing of the question. Do you want to script to provide the input or do you want to only continue if the user supplies the desired input???
If you don’t desire the player to actually give the game input you shouldn’t use the input system at all. For example in this case I would just call the method invoked by pressing C after the players “deathEvent” or as it’s last instruction.
As darthbator said, you do not actually simulate an input, you just do what would be done if the key was pressed. But here is an example on how you could do it.
//When the player dies, set this variable to true
var playerJustDied : Boolean = false;
function LateUpdate() {
//If c is pressed, or player just died
if(Input.GetButton("c") || playerJustDied){
keyCpressed();
//Set it to false again, so c is not pressed over and over
if(playerJustDied)
playerJustDied = false;
}
}
}
function keyCpressed(){
Debug.Log('Do what should be done when c is pressed or player died');
}