using UnityEngine; public class PlayerMovement : MonoBehaviour { public Rigidbody rb; public float speed=500; public float hSpeed=200; bool mvLeft, mvRight = false; // Start is called before the first frame update void Start() { } // Update is called once per frame void Update() { mvRight=Input.GetKey("d"); mvLeft=Input.GetKey("a"); } void FixedUpdate() { rb.AddForce(0,0,speed * Time.deltaTime); if (mvRight) { rb.AddForce(hSpeed * Time.deltaTime, 0, 0, ForceMode.VelocityChange); } if (mvLeft) { rb.AddForce(-hSpeed * Time.deltaTime, 0, 0, ForceMode.VelocityChange); } if (rb.position.y < -1f) { FindObjectOfType().EndGame(); } } }