objectをクリックすることでカウンターの数字が上がっていくものを作りたいのですが、最初の一回目のクリックで0となり二回目以降で1,2,3と上がっていってしまいます。最初のクリックで1、二回目で2,、、、というようにするにはどうしたらいいでしょうか。
また、任意の桁数に到達すると0に戻るには何のコードを追加すればいいでしょうか。
(例、任意の桁が4桁なら、9999の次にクリックすると10000に行かず0に戻る)
///
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;
public class Counter : MonoBehaviour,IPointerClickHandler
{
public GameObject score_object = null; // Textオブジェクト
public int score_num = 0;
// Start is called before the first frame update void Start() { } // Update is called once per frame void Update() { } public void OnPointerClick(PointerEventData eventData) { Text score_text = score_object.GetComponent<Text>(); // テキストの表示を入れ替える score_text.text = "Score:" + score_num; score_num += 1; }
}

下記のような回答は推奨されていません。
このような回答には修正を依頼しましょう。
また依頼した内容が修正された場合は、修正依頼を取り消すようにしましょう。
2022/09/25 07:27