if(Input.GetKeyUp(“s”) && Input.GetKeyDown(“p”))
{
Instantiate(shot, shooter.position, shooter.rotation);
}
else if(Input.GetKeyDown("s") && Input.GetKeyDown("p"))
{
Instantiate(shot, downShooter.position, downShooter.rotation);
}
if(Input.GetKeyUp(“s”) && Input.GetKeyDown(“p”))
{
Instantiate(shot, shooter.position, shooter.rotation);
}
else if(Input.GetKeyDown("s") && Input.GetKeyDown("p"))
{
Instantiate(shot, downShooter.position, downShooter.rotation);
}
I don’t think that you can have multiple key-press (input) statements in one if statement. So I’d change it so you only have to press one key.
Are you really wanting &&? Do you want either key pressed or do they both need to be pressed?
If you’re wanting to have either, just change the ‘&&’ to ‘||’…
if(Input.GetKeyUp("s") || Input.GetKeyDown("p"))
{
Instantiate(shot, shooter.position, shooter.rotation);
}
else if(Input.GetKeyDown("s") || Input.GetKeyDown("p"))
{
Instantiate(shot, downShooter.position, downShooter.rotation);
}
What are you trying to achieve?
Update based on feedback:
Ok if I understand what you need this should work:
var isSDown = false;
function Update () {
if(Input.GetKeyDown("s")) {
isSDown = true;
} else if(Input.GetKeyUp("s")) {
isSDown = false;
}
if((isSDown == false) && Input.GetKeyDown("p"))
{
Debug.Log("p Pressed when s is NOT down");
}
else if(isSDown && Input.GetKeyDown("p"))
{
Debug.Log("p Pressed when s is IS down");
}
}
Sample code:-
function Update () {
if(Input.GetKeyUp(KeyCode.S) || Input.GetKeyDown(KeyCode.P))
{
Debug.Log("S up or P down");
}
else if(Input.GetKeyDown(KeyCode.S) || Input.GetKeyDown(KeyCode.P))
{
Debug.Log("S down or P Down");
}
}
That is a fixation on your code, however I do have another code sample that I can re-write from scratch to show you how I would do it.