using System.Collections; using System.Collections.Generic; using UnityEngine; public class Movement2D : MonoBehaviour { public float moveSpeed = 10f; public float jumpForce = 10f; public bool isGrounded; private SpriteRenderer sprite; public void Start() { sprite = gameObject.GetComponent(); } private void Update() { Jump(); Vector3 movement = new Vector3(Input.GetAxis("platformerHorizontal"), 0f, 0f); transform.position += movement * Time.deltaTime * moveSpeed; if (Input.GetAxis("platformerHorizontal") > 0) { sprite.flipX = false; } else if (Input.GetAxis("platformerHorizontal") < 0) { sprite.flipX = true; } } void Jump() { if (Input.GetButtonDown("Jump") && isGrounded) { gameObject.GetComponent().velocity = (new Vector2(0f, jumpForce)); } } }