Respawn approach theory

I’m developing a game with 5 spawn points that each spawn 8 pieces in a row. When a player gets a match, I want those pieces to vanish and be replaced by new pieces. Those pieces would spawn from the appropriate spawn points to keep the proper number of pieces per row. Now originally I thought I would accomplish this by assigning a game tag to each piece spawned according to the spawn point.

However it seems that method is impossible to use. From what I can tell, there is no way to assign a game tag through code on a spawned prefab. I’m wondering how else I can approach this.

The setup looks like:

S1. S2. S3. S4. S5. <Spawn points
X. Y. Z. A. B.
X. Y. Z. A. B.
X. Y. Z. A. B.
X. Y. Z. A. B.
X. Y. Z. A. B.
X. Y. Z. A. B.
X. Y. Z. A. B.
X. Y. Z. A. B. <rows

Assuming each variable is a randomly spawned prefab, how would you update a specific row in the absence of using game tags to keep track of them?

There are lots of ways to solve this. An easy way would be to create a new component called “SpawnHistory” that holds a reference to where the object spawned from and add it to each gameobject a spawn point creates.

As TheShane said, there are many ways of doing it.

if you get a match, you’ll remove those blocks. Right? While, during that code bit you could…

if (myblocksposition = whatever your side to side axis is) MyRowNumber = 1;
if (myblocksposition = whatever your side to side axis is) MyRowNumber = 2;

granted, that’s a lot of if statements, and it might be easier with a case… anywho, you could determine what “Row” your block is… then, call that row’s spawner to…spawn a new block.

Ok I think I’ll go the SpawnHistory route. I’ve created a component to attach to each prefab to hold it. In this case, I called the component class “SpawnTracker”

public class SpawnTracker : MonoBehaviour {

	public Object spawnID;

Ok so now I have to figure out how to get the Spawner to input a value into that variable. They are not attached to the same GameObject.

I’m figuring I have to do it in this area of that code:

void SpawnStart() {
		    // Define Prefab Array
		    PrefabArr = Resources.LoadAll<GameObject>("Prefabs");
			// get random prefab
			int randomSpwn = Random.Range(0, PrefabArr.Length);
			//instantiate Prefab
			Instantiate(PrefabArr[randomSpwn], Spawner.transform.position, Quaternion.identity);
                       // IM THINKING HERE, BUT THAT DID STOP THE FUNCTION LAST TIME
	}

	//Start Game Spawner Coroutine
	IEnumerator StartGame() {
		for(int i=0; i<rows; i++) {   
			SpawnStart();
                        // OR HERE?  
			yield return new WaitForSeconds(fSpawnDelay);
		}
	}

Also the code seems to be very finicky when it comes to accessing data from another class. Not sure how I would do it properly. I’ve tried the FindObjectOfType route to no avail. Documentation seems pretty sketchy. Do the components need to be on the same GameObject or no?