unity 自作サイコロゲームで出た目を文字として出力したい

前提

イメージ説明
unityでサイコロを作っており、サイコロとしては完成しました。
加えて、出た目に対応して画面に文字で「出た目は◯です」と出力したい(この画像では3)のですが、解決することができませんでした。
ご享受願います。

該当のソースコード

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class DiceScript : MonoBehaviour
{
public int count; //サイコロの目の変数
[SerializeField] Sprite[] diceArray; //サイコロの画像入れる変数
private SpriteRenderer diceSprite; //サイコロのスプライトを表示させるためのコンポーネント
private bool isStop; //サイコロを止まっているかどうか判断するためのブール

void Start() // スタートボタンが押されたら以下のコードが始動 { count = Random.Range(1,7); //1以上7未満でランダムな変数を出力 isStop = false; //is stopをfalseに設定 diceSprite = GetComponent<SpriteRenderer>();//サイコロの画像を動かすコンポーネント } void Update() //動いてる時のプログラム { if (Input.GetMouseButtonDown (0) && !isStop)//マウスが左クリックされたときサイコロが止まっていなかったら止めるプログラム { isStop = true; //サイコロが止まっているのでis stopをtrueに設定 } else if (Input.GetMouseButtonDown (0) && isStop)//もし左クリックされているときにサイコロが止まっていたら動かすプログラム { isStop = false; //サイコロが動いているのでis stopをfalseに設定 } if (!isStop) //is stopがfalseの場合下記のプログラムを実行 { count = Random.Range(1,7); //1以上7未満の数をcount変数に出力された数に設定された画像を画面に表示 if(count == 1) { diceSprite.sprite = diceArray[0]; } if(count == 2) { diceSprite.sprite = diceArray[1]; } if(count == 3) { diceSprite.sprite = diceArray[2]; } if(count == 4) { diceSprite.sprite = diceArray[3]; } if(count == 5) { diceSprite.sprite = diceArray[4]; } if(count == 6) { diceSprite.sprite = diceArray[5]; } } }

}

コメントを投稿

0 コメント