I am very new on developing games. I decided to make a game simply with a player and 5 different objects around it. Any time player collides with the one of the object, then all objects destroyed and respawn again. So far i managed to destroy them but couldt respawn them.
Could you please help me about it, Thank you
here is the code
public class collectibles : MonoBehaviour
{
public GameObject[] spawncollectable;
bool isobjdestroyed=false;
void Start()
{
float radians = 2 * Mathf.PI * 1.3f;
float vert = Mathf.Sin(radians);
float horiz = Mathf.Cos(radians);
var spawnDir = new Vector3(horiz + Random.Range(-0.1f, 1.3f), 0.2f, vert + Random.Range(-0.1f, -1.3f));
var spawnPos = transform.position + spawnDir;
Instantiate(spawncollectable[Random.Range(0, spawncollectable.Length)],spawnPos, Quaternion.identity);
}
private void Update()
{
if (isobjdestroyed == true)
{
float radians = 2 * Mathf.PI * 1.3f;
float vert = Mathf.Sin(radians);
float horiz = Mathf.Cos(radians);
var spawnDir = new Vector3(horiz + Random.Range(-0.1f, 1.3f), 0.2f, vert + Random.Range(-0.1f, -1.3f));
var spawnPos = transform.position + spawnDir;
Instantiate(spawncollectable[Random.Range(0, spawncollectable.Length)], spawnPos, Quaternion.identity);
}
}
private void OnTriggerEnter(Collider other)
{
if (other.gameObject.tag == "Player")
{
GameObject[] obje = GameObject.FindGameObjectsWithTag("obj");
foreach (GameObject o in obje)
{
GameObject.Destroy(o);
isobjdestroyed = true;
}
}
}
}