Dice rolling
This commit is contained in:
50
Assets/Scripts/Dice.cs
Normal file
50
Assets/Scripts/Dice.cs
Normal 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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user