TL;DR How can I make filled true if 1 object is in the same position and not all of them? (I had an else statement doing the same thing previously, but changed it to this assuming that was the problem.)
Hello, my drag drop script checks if transform positions match to swap items and organize them for inventories and hotbars. When an item is in the same position as an inventory slot it gets set to filled. I thought it was all working fine until recently I realized that when I added an else to make sure filled gets set to false when an item isn't equal to it's position (When an item gets consumed, moved, etc.), but when I have the else statement on filled is locked to false. I did some testing and the script works properly when there's only 1 item in the array and doesn't when there's more, so I'm assuming it's comparing all of them to see if every single position matches. How can I make it check if atleast 1 position matches for it to become true. Here's what the code in question looks like.
private void Update()
{
foreach (GameObject g in Updater.barred)
{
if (g.transform.position == this.transform.position)
{
this.filled = true;
}
}
}
private void LateUpdate()
{
foreach (GameObject g in Updater.barred)
if (this.transform.position != g.transform.position)
{
this.filled = false;
}
}