list check doesnt work anymore

I tried it this way but the Image doesn’t go away when it’s in the inventory.
How can I fix this?
When I pick it up it should check for the name in the list(inventory), and then if it’s in, remove the Image.

[SerializeField] private Image Paper;

    public string name;


    void Start () {
        Paper.enabled = false;

    }
	

	void Update () {
     
        if (Input.GetKeyUp(KeyCode.E))
        {
            goAway()
        }
    }

    void goAway()
    {
        for (int i = 0; i < Inventory.instance.items.Count; i++)
        {
            if (Inventory.instance.items*.name == name)*

{
//remove image

}

}
}

private void OnMouseOver()
{

Paper.enabled = true;

}

private void OnMouseExit()
{

Paper.enabled = false;

}
}

I think your name check is the cause of the error. You compare the two names of type String with a “==”, which checks for the reference (or pointer). So, unless your names point to the same String object, you will always get “false” as a result.

[This][1] stackoverflow post describes it further.

You should always compare two Strings by using

if (Inventory.instance.items*.name.Equals(name)){*


}
[1]: c# - Are string.Equals() and == operator really same? - Stack Overflow