I'm using the line of code if (Input.GetKey("left"))
, but it obviously didn't register the input of the arrow key. How can I detect arrow keys like this?
My code is as follows:
using UnityEngine;
using System.Collections;
public class PlayerMovement : MonoBehaviour
{
public Rigidbody rb;
public float forwardForce = 2750f;
public float sidewaysForce = 150f;
void FixedUpdate()
{
rb.AddForce(0, 0, forwardForce * Time.deltaTime);
if (Input.GetKey("a"))
{
rb.AddForce(-sidewaysForce * Time.deltaTime, 0, 0, ForceMode.VelocityChange);
}
else
{
if (Input.GetKey("left")
{
rb.AddForce(-sidewaysForce * Time.deltaTime, 0, 0, ForceMode.VelocityChange);
}
}
if (Input.GetKey("d"))
{
rb.AddForce(sidewaysForce * Time.deltaTime, 0, 0, ForceMode.VelocityChange);
}
else
{
if (Input.GetKey("right"))
{
rb.AddForce(sidewaysForce * Time.deltaTime, 0, 0, ForceMode.VelocityChange);
}
}
if (rb.position.y < -1f)
{
FindObjectOfType<GameManager>().EndGame();
}
}
}