GetKeyDown Not Functioning When Two Unrelated GetKeys are True
So I am working on a game in which you can move around and cast abilities. How it's setup is that the character has a PlayerControls script, where the user can input various control schemes to their liking. Another script, Fireball uses these control inputs to determine when the ability should be cast when a button is hit. In the PlayerControls script, if statements with Inputs determine when the character should stand still, move left, move right, and jump, and sends that information to a completely separate script called PlayerMove, which just moves the character based on the input. The thing you need to understand is that PlayerMove and Fireball are completely separated, and should have no interactions whatsoever. Furthermore, the abilities cast perfectly when the character is standing still, moving left, moving right, with or without jumping, however it doesn't even register a button press when the user inputs the left and right command at the same time.
public class Fireball : PlayerAbility {
[SerializeField]
[Range(0f, 100f)]
private float speed = 10f;
[SerializeField]
private bool accelerate = true;
[SerializeField]
[Range(0f, 10f)]
private float duration = 0f;
private int flip = 1;
private ConstantForce2D myForce;
// Use this for initialization
void Start () {
myForce = GetComponent<ConstantForce2D>();
if (GameObject.Find("Player"))
{
if (GameObject.Find ("Player").transform.Find ("AbiltityPoint").position.x - GameObject.Find ("Player").transform.position.x < 0) {
flip = -1;
} else {
flip = 1;
}
if (flip == 0)
flip = 1;
}
Destroy(gameObject, duration * 40 * Time.fixedDeltaTime);
}
// Update is called once per frame
void Update () {
if (accelerate)
{
myForce.force = new Vector3(speed * flip, 0f, 0f);
}
else
{
myForce.force = Vector3.zero;
GetComponent<Rigidbody2D>().velocity = new Vector3(speed * flip, 0f, 0f);
}
}
}
In PlayerControls:
float HorizontalMovement()
{
if (Input.GetKey(left) && !Input.GetKey(right))
{
return -1f;
}
else if (Input.GetKey(right) && !Input.GetKey(left))
{
return 1f;
}
else if (Input.GetKey(right) && Input.GetKey(left))
{
return 0f;
}
else
{
return 0f;
}
}
Anyone have any idea what's going on here? Thanks.