using System.Collections; using System.Collections.Generic; using Unity.VisualScripting; using UnityEngine; using UnityEngine.InputSystem; using TMPro; public class PlayerController : MonoBehaviour { //the number of collected items int count; // public TextMeshProUGUI countText; // 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; //Reset Flag bool resetFlag = false; // Start is called before the first frame update. void Start() { // Get and store the Rigidbody component attached to the player. rb = GetComponent(); count = 0; SetCountText(); } void SetCountText() { countText.text = "Count: " + count.ToString(); } // 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; } void OnRST() { Debug.Log("Reset"); resetFlag = true; } void OnTriggerEnter(Collider other) { if (other.gameObject.CompareTag("PickUp")) { other.gameObject.SetActive(false); count++;//count = count+1; SetCountText(); } } // 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); if (resetFlag) { rb.position = new Vector3(0.0f, 0.5f, 0.0f); rb.velocity = Vector3.zero; rb.rotation = Quaternion.identity; rb.angularVelocity = Vector3.zero; resetFlag = false; } } }