- Home /
How to hide an object from array instead of removing it?
I have successfully made it so that when a certain number of commands pass, item i from my array is removed, and I got this to work, though this isn't exactly what I want to do. It would be much easier for me if I could simply HIDE the object in the array until I need to make it visible again. I have absolutely no idea how to do this. This is all displayed on my user interface (UI). Here is my code:
public void testing(Item item)
{
if (contentPanel.name == "Home Content") {
for (int i = this.itemList.Count - 1; i >= 0; i--) {
if (this.itemList [i].dateButtonAdded.ToString () != logDate.text)
{
this.itemList.RemoveAt (i);
GameObject toRemove = transform.GetChild (i).gameObject;
buttonObjectPool.ReturnObject (toRemove);
}
}
}
}
Answer by JedBeryll · May 05, 2018 at 04:29 AM
As far as I know there is no such thing in C# (or any language). Instead you could keep another list with the currently used items. By the way, you're clearly using a list and not an array so to avoid confusion you should call it a list.
Whoops sorry, my bad. And okay thanks. I was going to try doing that, but I just wanted to make sure that there wasn't a shortcut first.