Finding all the Weapons a Character is Holding via Tag – Unity3D Bolt Micro-Tutorial

This entry is part of a series of tips I am creating as I make my game.

You can use Bolt for free by downloading it from the Asset Store.

Details

What we need: A list of all game objects on a character with a specific tag.

Input: The character game object that has the weapons you are looking for. These weapons should have a specific tag attached (such as ‘Attack’).

Output: A list of game objects attached to that character with the specified tag (such as ‘Attack’).

How this saves you time: No more manually filling lists; just attach this script anywhere on the character and then any weapon you attach to the character is automatically found so long as it has the specified tag.

Summary: Let’s say that you’ve applied the ‘Attack’ tag to game objects (Lets call these ‘Weapons’) in your scene that are attached to a specific character. You have the Axe weapon, the Sword weapon, and the Spear weapon. If your scene contained many characters, you would want a method for each character to identify which weapons are theirs.

Output

The list you would end up with.

How to Implement

How to implement this in Bolt.
  1. Find all game objects with the specified tag. (This searches the entire scene)
  2. For each object found, check to see if the root transform of the found object matches the root transform of the object this script is attached to.
  3. If they match, add the object to a Game Object List.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: