How to save many instantiated objects position/rotation at runtime???

Hello, I want to create game like minecraft (sandbox) and I have a problem with saving a new blocks. I’m using actually this method How to save instantiated gameObject ?????? - Questions & Answers - Unity Discussions and it works but I can save only one last block. I tried to serialize it, PlayerPrefs, saving data to text file and saving by table but my knowledge about tables is low :stuck_out_tongue: Please help ^^

2 Answers

2

bool tapOnce;
public List saveGameObjects;

public GameObject[] itemToSpawn;

void Update(){
	if (Input.GetMouseButtonUp(0))
	{
		Vector3 mousePos = new Vector3(Input.mousePosition.x, Input.mousePosition.y, 5);
		Vector3 lookPos = Camera.main.ScreenToWorldPoint(mousePos);
		if (tapOnce){
			tapOnce=false;
			int itemNo = Random.Range(0, 4);
			GameObject go = Instantiate(itemToSpawn[itemNo]) as GameObject;
			
			saveGameObjects.Add(go);
			
		}
	}
}

This works pretty well for me. Hope this helps you.
Don’t forget to use:

  using System.Collections.Generic;

You should try to check this…