i need to add ray perception sensor 2d to 2d agent on unity, here's my PlayerController.cs:

using UnityEngine;
using Unity.MLAgents;
using Unity.MLAgents.Actuators;
using Unity.MLAgents.Sensors;
using Unity.MLAgents.Sensors.Reflection;

[AddComponentMenu("")]
public class PlayerController : Agent
{
    public float speed = 5f;

    private Rigidbody2D rb;
    private FoodSpawner foodSpawner;
    private Vector3 initialPosition;

    private void Start()
    {
        rb = GetComponent<Rigidbody2D>();
        initialPosition = transform.position;
    }

    void Update()
    {
        ManageEpisode();
    }

    private void ManageEpisode()
    {
        SharedAcademy.EpisodeTimeout -= Time.deltaTime;
        
        int remainingFoodCount = foodSpawner.GetComponentsInChildren<Food>().Length;

        if (SharedAcademy.EpisodeTimeout <= 0 || remainingFoodCount == 0)
        {
            ResetPlayerEpisode();
            foodSpawner.SpawnFood();
            SharedAcademy.EpisodeTimeout = 30f;
        }
    }


    public override void OnEpisodeBegin()
    {
        rb.velocity = Vector2.zero;

        // Get Training Area position
        Vector3 trainingAreaPosition = foodSpawner.transform.position;

        // Calculate the random position relative to the Training Area
        float randomX = UnityEngine.Random.Range(-foodSpawner.spawnRange, foodSpawner.spawnRange) + trainingAreaPosition.x;
        float randomY = UnityEngine.Random.Range(-foodSpawner.spawnRange, foodSpawner.spawnRange) + trainingAreaPosition.y;

        initialPosition = new Vector3(randomX, randomY, 0);
        transform.position = initialPosition;
    }

    
    public override void CollectObservations(VectorSensor sensor)
    {
        // The observations from ray-based sensor will be automatically collected
    }

    /*public override void CollectObservations(VectorSensor sensor)
    {
        // Agent’s position
        sensor.AddObservation(transform.position);
        sensor.AddObservation(rb.velocity);

        if (foodSpawner != null)
        {
            // Distance calculations
            float minDistance = float.MaxValue;
            Vector2 closestFoodPos = Vector2.zero;
            int addedFoodObs = 0;
            int maxFoodObserve = 10; // Set a maximum number of food items to track.

            foreach (var food in foodSpawner.GetComponentsInChildren<Food>())
            {
                float distance = Vector2.Distance(transform.position, food.transform.position);
                if (addedFoodObs < maxFoodObserve)
                {
                    sensor.AddObservation(food.transform.position); // Add the food position to the observations
                    addedFoodObs++;
                }
                if (distance < minDistance)
                {
                    minDistance = distance;
                    closestFoodPos = food.transform.position;
                }
            }

            // Add closest food position and distance
            sensor.AddObservation(closestFoodPos);
            sensor.AddObservation(minDistance);
        }
    }*/

    public override void OnActionReceived(ActionBuffers actions)
    {
        float moveHorizontal = actions.ContinuousActions[0];
        float moveVertical = actions.ContinuousActions[1];

        Vector2 movement = new Vector2(moveHorizontal, moveVertical);
        rb.AddForce(movement * speed);

        float minDistance = float.MaxValue;
        foreach (var food in foodSpawner.GetComponentsInChildren<Food>())
        {
            float distance = Vector2.Distance(transform.position, food.transform.position);
            if (distance < minDistance)
            {
                minDistance = distance;
            }
        }

        // Add a penalty proportional to the distance to the nearest food.
        SetReward(-minDistance * Time.fixedDeltaTime);
    }

    public void AddRewardOnEatingFood()
    {
        AddReward(1f);
    }

    public override void Heuristic(in ActionBuffers actionsOut)
    {
        var continuousActionsOut = actionsOut.ContinuousActions;
        continuousActionsOut[0] = Input.GetAxis("Horizontal");
        continuousActionsOut[1] = Input.GetAxis("Vertical");
    }

    public void ResetPlayerEpisode()
    {
        EndEpisode();
        transform.position = initialPosition; // Reset player position to the initial position
        rb.velocity = Vector2.zero;
    }

    public void SetFoodSpawner(FoodSpawner spawner)
    {
        foodSpawner = spawner;
    }
}