using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CoinSpawning : MonoBehaviour
{
public GameObject coinPrefab;
private void OnCollisionEnter(Collision other)
{
if (other.gameObject.name == "Coin" || other.gameObject == coinPrefab)
{
StartCoroutine(coinSpawn());
Destroy(other.gameObject);
}
}
IEnumerator coinSpawn()
{
yield return new WaitForSeconds(3f);
spawnCoin();
}
private void spawnCoin()
{
GameObject a = Instantiate(coinPrefab) as GameObject;
a.transform.position = new Vector3(Random.Range(-50, 50), Random.Range(1, 2), Random.Range(-50, 50));
}
}