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));
}
}
If you don’t like using tags you can accomplish this with small changes, when Instantiate creates a game object it sets the name to “Coin (clone)”.
you can change your OnCollisionEnter to if (other.gameObject.name.Contains("Coin"))
or you can modify spawnCoin() and set a name for the new game object like so:
GameObject a = Instantiate(coinPrefab) as GameObject;
a.name = "Coin";
@drthirtle So I’m new to this as well but this may help.
When you instantiate a new game object it is created with the name “Coin (clone)”. You are checking for just “Coin”.
Either name the game object when creating it like so:
spawnCoin() {
GameObject a = Instantiate(coinPrefab) as GameObject;
a.name = "Coin";
...
}
or in your collision check use:
if (other.gameObject.name.Contains("Coin")) {...}
Let me know if this was helpful 
If I understand correctly, I think you should use tags. For example, set the coinPrefab’s tag to “Coin”, and in OnCollisionEnter check whether other.gameObject has that tag or not.