魔法のメモ

CG N GAME BLOG

C#_Unity_逆引き05

■コインカウント

f:id:heroroom:20211102094249p:plain

f:id:heroroom:20211102094251p:plain

■ScoreText

using UnityEngine.UI;

public class ScoreText : MonoBehaviour
{
    Text text;
    public static int coinAmount;

    // Start is called before the first frame update
    void Start()
    {
        text = GetComponent<Text>();
    }

    // Update is called once per frame
    void Update()
    {
        text.text = coinAmount.ToString();
    }
}

■Coin

private void OnTriggerEnter(Collider other)
    {
        ScoreText.coinAmount += 1;
        Destroy(gameObject);
    }