UnityScripterAI
Discord ↗
Link Copied to Clipboard
×
"spawn coin object on hit"
using UnityEngine; public class CoinSpawner : MonoBehaviour { public GameObject coinPrefab; public Transform spawnPoint; void OnCollisionEnter(Collision collision) { if (collision.collider.CompareTag("Player")) { SpawnCoin(); } } void SpawnCoin() { GameObject coin = Instantiate(coinPrefab, spawnPoint.position, Quaternion.identity); } }