- Home /
Adding an attribute/type to a transform or object
Hi,
I have a number of spawn positions in my level and would like to categorise them into Left, Right, Top so that I know how to begin moving the enemy that spawns at each one.
I was thinking that an Enum type might do the trick, but I'm not too sure how to relate the type with my spawnpoint transforms.
I have started the following script and would like to be able to assign each one in the following way:
spawnpoint1.selectedSide.Left;
So far, my script is as follows:
public class SpawnPoint_Manager : MonoBehaviour
{
enum SpawnSide
{
DEBUG_ITEM,
LEFT,
RIGHT,
MIDDLE,
COUNT_NUM_ITEMS
}
enum SpawnType
{
DEBUG_ITEM,
FLOOR,
PIPE,
COUNT_NUM_ITEMS
}
public List<Transform> thisFloorSpawnpointPosList;
public SpawnPoint_Manager.SpawnSide spawnpointSide;
public SpawnPoint_Manager.SpawnType spawnpointType;
void Start()
{
.
.
//Note: the 'child' objects are the outer objects inside the
// thisFloorSpawnpointPosList List with the 'innerChild' objects inside
// them, which are the actual spawnpoint transforms.
//spawnpoint transforms
//look into each of these Spawner object's children
foreach (Transform innerChild in child)
{
// and check whether their children's names begin with the following (these are the actual Spawnpoint transforms)
if (innerChild.name.StartsWith("spawnpoint"))
{
// Add the Spawnpoint transform to the FloorSpawnpointPosList list
thisFloorSpawnpointPosList.Add(innerChild);
if (innerChild.name.Contains("left"))
{
// Set the selectedSide and selectedType for the spawnpoint transform
//innerChild.selectedSide.Left;
}
}
}
}
}
I've named them with _left, _right, etc., so they can be sorted but I would like to create a type so that in another script, which controls the paths, I can select which to use based on where the enemy is spawning. So if at a _left spawnpoint, then use the path that moves to the right.
So, in that script I could do something like:
if (spawnpoint.selectedSide = LEFT) Use left path for enemy
that should work.. but in your other script, it will need to be like:
if (spawnpoint.spawnpointSide == SpawnSide.LEFT)
//Do something
also you can use tags to tag a gameobject
gameobject.tag = "LEFTSPAWN"
if gameobject.tag == "LEFTSPAWN"
Your answer
![](https://koobas.hobune.stream/wayback/20220613083512im_/https://answers.unity.com/themes/thub/images/avi.jpg)