UnityScripterAI
Discord ↗
Link Copied to Clipboard
×
"create coin object"
using UnityEngine; public class Coin : MonoBehaviour { public int coinValue = 1; public float rotationSpeed = 100f; // Update is called once per frame void Update() { // Rotate the coin object transform.Rotate(Vector3.up, rotationSpeed * Time.deltaTime); } void OnTriggerEnter(Collider other) { if (other.CompareTag("Player")) { // Add coin value to the player's score other.GetComponent<PlayerScore>().AddScore(coinValue); // Destroy the coin object Destroy(gameObject); } } }