Hey there and welcome to the forum,
not completly sure where you are heading with this but from the information given i’d strongly suggest to take 2 steps back and to choose a slightly different approach. Having something like and array of bools might look like an easy solution at first but can get quite tiresome as soon as you have more objects like 10-20 onwards.
So given this let’s take a look at some techniques that can be used to deal with this:
First up check out Enumerations
// this "enum" type can be used to create a List of "Names" that translate into numbers which can be use as indexes.
public enum ItemType { None, Knife, Pencil, Gun, Shield, Sword };
//if you now give this variable to a script you can set the "Type" in the inspector from a Dropdown menu.
public ItemType type;
enums can help to make your code really readable as you can have comparisons like this:
if(type == ItemType.Knife)
//do something because this is a knife.
Another thing that you should look into is Inheritance.
For example you could create a class:
public class CollectibleItem : MonoBehaviour
{
public virtual void Use() {} //this here can stay empty as the base class does not need behaviour here. It is only there to create the "structure" of an item.
}
On this you can now build Items which are derived from the CollectibleItem base class: (each of these have to go into their own file like if you create a new script for any Monobehaviour)
public class Knife : CollectibleItem {
public override void Use() {
//do whatever a knife should do specifically if you "Use" this item.
}
}
public class Pencil: CollectibleItem {
public override void Use() {
//do whatever a pencil should do specifically if you "Use" this item.
}
}
What can we use this for? If you have a player script you can now do the following:
public class YourPlayerScript : Monobehaviour {
// List for Collectible Items:
public List<CollectibleItem> inventory = new List<CollectibleItem>();
public void OnCollisionEnter(Collision col)
{
var collectible = col.gameObject.GetComponent<CollectibleItem>();
if(collectible == null)
return; // do nothing if this is not a collectible
//if we are here then it is a collectible so we can do something with it:
//for example use it:
collectible.Use(); //this will now call the "Use" function. This will always call the "override" behaviour from the derived classes like "Knife" or "Pencil".
//or add it to our Inventory:
inventory.Add(collectible);
//or check if it is a specific collectible:
if(collectible is Pencil)
//do something specific since it is a pencil
}
}
As shown above you can use this class inheritance base to easily handle different objects in a generalized manner. Most importantly though, you can easily add more. Just add a new derived class from CollectibleItem. It will automatically work with your inventory, you can easily give it its own behaviour.
Let me know if something was unclear here. I know that this might be a bit much since you are still at the start of your journey but i can only encourage you to try and understand these methods/principles as they will save you a lot of pain further down the road.