2022-10-30 15:02:17 +01:00
|
|
|
|
using System.Collections;
|
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
|
|
|
|
public class Dice : MonoBehaviour {
|
|
|
|
|
|
public Sprite[] diceSides = new Sprite[6];
|
2022-11-02 11:15:11 +01:00
|
|
|
|
public SpriteRenderer hely1;
|
|
|
|
|
|
public SpriteRenderer hely2;
|
2022-11-02 13:19:01 +01:00
|
|
|
|
public SpriteRenderer akcioponthely;
|
2022-10-30 15:02:17 +01:00
|
|
|
|
|
2022-11-02 12:52:21 +01:00
|
|
|
|
private int[] diceResult = { 0, 0 };
|
|
|
|
|
|
public int valasztottErtek; //a jatekos altal valasztott dobott ertek helye
|
|
|
|
|
|
private bool locked = false; //ne lehessen ujra kivalasztani a masikat ha mar tortent egy valasztas
|
2022-10-30 15:02:17 +01:00
|
|
|
|
|
2022-11-02 13:15:47 +01:00
|
|
|
|
//getters setters
|
|
|
|
|
|
public int[] getDices() { return diceResult; }
|
|
|
|
|
|
public int getValasztottErtek() { return valasztottErtek; }
|
|
|
|
|
|
public void setValasztottErtek(int ujErtek) { valasztottErtek = ujErtek; }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void ertekValasztas(GameObject gomb) {
|
2022-11-02 12:52:21 +01:00
|
|
|
|
if (diceResult[0] != 0 && diceResult[1] != 0 && !locked) { //megnezzuk hogy lett e mar dobva es nem valasztott meg a jatekos
|
2022-11-02 13:15:47 +01:00
|
|
|
|
if (gomb.name == "dice1btn") {
|
2022-11-02 12:52:21 +01:00
|
|
|
|
valasztottErtek = diceResult[0];
|
2022-11-02 13:15:47 +01:00
|
|
|
|
|
|
|
|
|
|
//a valasztott szam atirasa az akcio mezobe
|
2022-11-02 13:19:01 +01:00
|
|
|
|
akcioponthely.sprite = diceSides[valasztottErtek-1];
|
|
|
|
|
|
akcioponthely.size = new Vector2(38, 38);
|
2022-11-02 13:15:47 +01:00
|
|
|
|
|
2022-11-02 12:52:21 +01:00
|
|
|
|
locked = true;
|
2022-11-02 13:15:47 +01:00
|
|
|
|
} else if (gomb.name == "dice2btn") {
|
2022-11-02 12:52:21 +01:00
|
|
|
|
valasztottErtek = diceResult[1];
|
2022-11-02 13:15:47 +01:00
|
|
|
|
|
|
|
|
|
|
//a valasztott szam atirasa az akcio mezobe
|
2022-11-02 13:19:01 +01:00
|
|
|
|
akcioponthely.sprite = diceSides[valasztottErtek-1];
|
|
|
|
|
|
akcioponthely.size = new Vector2(38, 38);
|
2022-11-02 13:15:47 +01:00
|
|
|
|
|
2022-11-02 12:52:21 +01:00
|
|
|
|
locked = true;
|
|
|
|
|
|
}
|
2022-10-30 15:02:17 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2022-11-02 12:52:21 +01:00
|
|
|
|
Debug.Log("valasztott ertek: " + valasztottErtek + "locked status: " + locked);
|
|
|
|
|
|
}
|
2022-11-02 11:15:11 +01:00
|
|
|
|
|
2022-11-02 12:52:21 +01:00
|
|
|
|
private int RollDice(SpriteRenderer renderer) {
|
|
|
|
|
|
int randomDiceSide = Random.Range(0, 5);
|
|
|
|
|
|
int finalSide = randomDiceSide + 1;
|
2022-11-02 11:15:11 +01:00
|
|
|
|
|
|
|
|
|
|
Debug.Log(finalSide);
|
|
|
|
|
|
|
|
|
|
|
|
return finalSide;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-11-02 12:52:21 +01:00
|
|
|
|
public void renderDice() {
|
2022-11-02 11:15:11 +01:00
|
|
|
|
do {
|
|
|
|
|
|
diceResult[0] = RollDice(hely1);
|
|
|
|
|
|
diceResult[1] = RollDice(hely2);
|
|
|
|
|
|
} while (diceResult[0] == diceResult[1]);
|
|
|
|
|
|
|
2022-11-02 12:52:21 +01:00
|
|
|
|
hely1.sprite = diceSides[diceResult[0]-1];
|
2022-11-02 11:15:11 +01:00
|
|
|
|
hely1.size = new Vector2(38, 38);
|
|
|
|
|
|
|
2022-11-02 12:52:21 +01:00
|
|
|
|
hely2.sprite = diceSides[diceResult[1]-1];
|
2022-11-02 11:15:11 +01:00
|
|
|
|
hely2.size = new Vector2(38, 38);
|
2022-10-30 15:02:17 +01:00
|
|
|
|
}
|
|
|
|
|
|
}
|