Relevant GameObject[].
I'm trying to make a picking objects up script and have gameobjects of a certain tag to be used depending on which one I'm trying to pick up. How do I do this using GameObject[]? I think it might be something like GameObject[relevant] or something or maybe a relevant int. Any help is appreciated.
Answer by UnityCoach · May 03, 2017 at 08:32 PM
If I understand well, you have an inventory of object to be used to pickup other objects.
Like, say you pick up a very small object, you put it in your wallet, and bigger one in your backpack, and a very big one on your shoulder?
If this case, you could have a pickable object script, with an enum that tells its kind. Then you'd have a picker script, which would reference objects to be used along different kinds. Then I guess you'd need some weighting if there are more than one object that can be used with the object to pick up. You could create a custom struct to store the object along its preference weight, so that you can sort it easily, using List.Sort() or Linq. If you are to have a different script for every pickable object you could also use interfaces, to tell what it can be used with. Like
public class FlashLight : MonoBahviour, ICanBeHandled, ICanBePutInBag, ICanBeSnappedToBelt {}
My advice would be to stay away from using tags for this, you may quickly run out of tags.
Actually. Thank you for the answer but that's not what I'm trying to do. I'm trying to make a restaurant game in which you have to grab and use 1 knife at a time, but I want to make this script not a component of the objects. I want to make this a 'process'.