using System.Collections; using System.Collections.Generic; using Unity.VisualScripting; using UnityEngine; using UnityEngine.InputSystem; public class PlayerController : MonoBehaviour { // Rigidbody of the player. private Rigidbody rb; // Movement along X and Y axes. private float movementX; private float movementY; // Speed at which the player moves. public float speed; //Jump Flag bool jumpFlag = false; // Start is called before the first frame update. void Start() { // Get and store the Rigidbody component attached to the player. rb = GetComponent(); } // This function is called when a move input is detected. void OnMove(InputValue movementValue) { // Debug.Log(movementValue); // Convert the input value into a Vector2 for movement. Vector2 movementVector = movementValue.Get(); // Store the X and Y components of the movement. movementX = movementVector.x; movementY = movementVector.y; } void OnJump() { Debug.Log("JUMP"); jumpFlag = true; } // FixedUpdate is called once per fixed frame-rate frame. private void FixedUpdate() { float forceUp = 0.0f; Vector3 movement; if ( jumpFlag) { forceUp = 200.0f; jumpFlag = false; } // Create a 3D movement vector using the X and Y inputs. movement = new Vector3(movementX, forceUp, movementY); // Apply force to the Rigidbody to move the player. rb.AddForce(movement * speed); } }