I will share 3 scripts consisting of a puzzle. In the PlayerInteraction script, instead of pressing E to call the Interact() function, i want to press E to call a OnGUI function in which I loop through my player inventory and list all of the name items containing the EldritchSymbol component. When the player click on one of the available item in the list, then it will call the Interact() function, and the player will place the item he clicked on under the current symbol transform. Also, I need anothe OnGUI function that list the name of the item in the symbol slot, and when the player clicks it, it returns back to the player inventory. I want the GUI to be center screen.

Script 1:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class LovecraftianPuzzle : MonoBehaviour
{
public enum EldritchSymbols { Nyarlathotep, Azathoth, Cthulhu, ShubNiggurath, YogSothoth }
public Transform[] symbolSlots;
public GameObject[] eldritchSymbolPrefabs;
public GameObject portal;
public Animator portalAnimator;
public AudioSource gatewayAudio;
public AudioClip placeSymbolSound;
private GameObject player;
private AudioSource playerAudioSource;




private void Start()
{
    player = GameObject.Find("Player");
    playerAudioSource = player.GetComponent<AudioSource>();
}
private List<EldritchSymbols> correctOrder = new List<EldritchSymbols>()
{
    EldritchSymbols.Nyarlathotep,
    EldritchSymbols.Azathoth,
    EldritchSymbols.Cthulhu,
    EldritchSymbols.ShubNiggurath,
    EldritchSymbols.YogSothoth
};

private List<EldritchSymbols> currentOrder = new List<EldritchSymbols>();

private Dictionary<EldritchSymbols, int> symbolToSlotIndex = new Dictionary<EldritchSymbols, int>()
{
{ EldritchSymbols.Nyarlathotep, 0 },
{ EldritchSymbols.Cthulhu, 2 },
{ EldritchSymbols.Azathoth, 1 },
{ EldritchSymbols.ShubNiggurath, 3 },
{ EldritchSymbols.YogSothoth, 4 }
};
public void PlaceSymbol(EldritchSymbols symbol)
{
int slotIndex = symbolToSlotIndex[symbol];
if (symbolSlots[slotIndex].childCount == 0)
{
GameObject symbolObject = Instantiate(
eldritchSymbolPrefabs[(int)symbol],
symbolSlots[slotIndex].position,
Quaternion.Euler(0, 24, -90), // Rotate 90 degrees around the Z axis
symbolSlots[slotIndex]);
if (!currentOrder.Contains(symbol)) // Check if the symbol is already in the list
{
currentOrder.Add(symbol); // Add it only if it's not present
}
playerAudioSource.PlayOneShot(placeSymbolSound);
}




    CheckPuzzleSolved();
}

private void CheckPuzzleSolved()
{
    if (currentOrder.Count == correctOrder.Count)
    {
        bool isSolved = true;

        for (int i = 0; i < correctOrder.Count; i++)
        {
            if (currentOrder[i] != correctOrder[i])
            {
                isSolved = false;
                break;
            }
        }

        if (isSolved)
        {
            StartCoroutine(GatewayAnimation());
        }
    }
}
public IEnumerator GatewayAnimation()
{
    portalAnimator.SetBool("OpenGateway", true);
    MeshCollider gatewayMeshFilter = portalAnimator.gameObject.GetComponent<MeshCollider>();
    gatewayAudio.Play();
    gatewayMeshFilter.enabled = false;
    yield return new WaitForSeconds(1f);
    portalAnimator.SetBool("OpenGateway", false);
}

public void ResetPuzzle()
{
    currentOrder.Clear();

    foreach (Transform slot in symbolSlots)
    {
        if (slot.childCount > 0)
        {
            Destroy(slot.GetChild(0).gameObject);
        }
    }
}

public void RemoveSymbol(EldritchSymbols symbol)
{
    // Find the index of the symbol in the currentOrder list
    int index = currentOrder.FindIndex(s => s == symbol);

    // Check that the index is valid
    if (index >= 0 && index < currentOrder.Count)
    {
        // Find the corresponding symbol in the symbolSlots array
        for (int i = 0; i < symbolSlots.Length; i++)
        {
            if (symbolSlots[i].childCount > 0)
            {
                GameObject symbolObject = symbolSlots[i].GetChild(0).gameObject;
                EldritchSymbols symbolInSlot = symbolObject.GetComponent<EldritchSymbol>().symbolType;

                if (symbolInSlot == symbol)
                {
                    // Remove the symbol from currentOrder and destroy the symbol object
                    currentOrder.RemoveAt(index);
                    playerAudioSource.PlayOneShot(placeSymbolSound);
                    Destroy(symbolObject);
                    break;
                }
            }
        }
    }
}
}

Script 2:
using UnityEngine;

public class EldritchSymbol : MonoBehaviour
{
public LovecraftianPuzzle.EldritchSymbols symbolType;
}

Script 3:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PlayerInteraction : MonoBehaviour
{
public float interactionDistance = 2f;
public LayerMask interactionMask;
private GameObject currentInteractable;
private GameObject lastPlacedSymbol;
void Update()
{
if (Input.GetKeyDown(KeyCode.E))
{
Interact();
}
}




void FixedUpdate()
{
    CheckForInteractions();
}

void CheckForInteractions()
{
    RaycastHit hitInfo;
    if (Physics.Raycast(transform.position, transform.forward, out hitInfo, interactionDistance, interactionMask))
    {
        if (hitInfo.transform.gameObject != currentInteractable)
        {
            currentInteractable = hitInfo.transform.gameObject;
            Debug.Log("New Interactable: " + currentInteractable.name);

            // You can add visual feedback or highlighting for the interactable object here.
        }
    }
    /*else
    {
        if (currentInteractable != null)
        {
            currentInteractable = null;
            Debug.Log("No interactable object in range.");

            // You can remove visual feedback or highlighting for the interactable object here.
        }
    }*/
}

void Interact()
{
    if (currentInteractable != null)
    {
        EldritchSymbol symbol = currentInteractable.GetComponent<EldritchSymbol>();
        if (symbol != null)
        {
            LovecraftianPuzzle puzzle = FindObjectOfType<LovecraftianPuzzle>();
            if (puzzle != null)
            {
                if (lastPlacedSymbol == currentInteractable)
                {
                    puzzle.RemoveSymbol(symbol.symbolType);
                    lastPlacedSymbol = null; // Reset the last placed symbol
                }
                else
                {
                    puzzle.PlaceSymbol(symbol.symbolType);
                    lastPlacedSymbol = currentInteractable; // Store the placed symbol
                }
            }
        }
    }
}
}

Here's an exemple on how I loop for Item name in my Inventory:
for (int t = 0; t < InvManager.Items; t++) //Starting a loop in the slots of the inventory:
{
if (InvManager.Slots[t].IsTaken == true) //Checking if there's an item in this slot.
{
Item ItemScript = InvManager.Slots[t].Item.GetComponent(); //Getting the item script from the items inside the bag.
if (ItemScript.Name == "ExempleName"){//Do stuff}