using UnityEngine; public class PlayerMovement : MonoBehaviour { public Rigidbody rb; public float runSpeed = 500f; public float strafeSpeed = 500f; public float jumpForce = 20f; protected bool strafeLeft = false; protected bool strafeRight = false; protected bool doJump = false; void Update() { if (Input.GetKey("d")) { strafeLeft = true; } else { strafeLeft = false; } if (Input.GetKey("a")) { strafeRight = true; } else { strafeRight = false; } if (Input.GetKeyDown("space") && IsJumpAllowed()) { doJump = true; } if (transform.position.y < -5f) { Debug.Log("Конец игры (y<-5)"); } if (transform.position.z > 480f) { Debug.Log("Полоса пройдена"); } } void FixedUpdate() { rb.AddForce(0, 0, runSpeed * Time.deltaTime); if (strafeLeft) { rb.AddForce(strafeSpeed * Time.deltaTime, 0, 0, ForceMode.VelocityChange); } if (strafeRight) { rb.AddForce(-strafeSpeed * Time.deltaTime, 0, 0, ForceMode.VelocityChange); } if (doJump) { rb.AddForce(Vector3.up * jumpForce, ForceMode.Impulse); doJump = false; } } bool IsJumpAllowed() { return (transform.position.y > 0f && transform.position.y < 1f) || (transform.position.y > 50f && transform.position.y < 100f) && (transform.position.x > -3f && transform.position.x < 3f); } }