Dice rolling

This commit is contained in:
2022-10-30 15:02:17 +01:00
parent 40c8963ec9
commit 1efd7c662b
28 changed files with 3878 additions and 210 deletions

50
Assets/Scripts/Dice.cs Normal file
View File

@@ -0,0 +1,50 @@
using System.Collections;
using UnityEngine;
public class Dice : MonoBehaviour {
public Sprite[] diceSides = new Sprite[6];
private SpriteRenderer rend;
private void Start () {
//Debug.Log("in");
rend = GetComponent<SpriteRenderer>();
// Innen szedi a képeket
//diceSides = Resources.LoadAll<Sprite>("\\Dice");
/*foreach (var t in diceSides) {
Debug.Log(t.name);
}*/
}
// Ha rákattintassz meghívja a RollTheDice-ot
public void OnMouseDown()
{
StartCoroutine("RollTheDice");
}
// A RollTheDice
private IEnumerator RollTheDice()
{
int randomDiceSide = 0;
int finalSide = 0;
for (int i = 0; i <= 20; i++)
{
randomDiceSide = Random.Range(0, 5);
rend.sprite = diceSides[Random.Range(0, 5)];
rend.size = new Vector2(40, 40);
yield return new WaitForSeconds(0.05f);
}
finalSide = randomDiceSide + 1;
Debug.Log(finalSide);
}
}