- Home /
Comparing in a dice game
want to make a 2D game , where every dice will be compared to the one in the opposite panel. It will basically look like in the attached image. I only don't know, how to create a script that will compare every pair of dice. I'm able to do it only with one pair. I want to make the number of dice customable. The die script is: using UnityEngine; using System.Collections; using UnityEngine.UI; public class NewBehaviourScript2sdf : MonoBehaviour {
public int n;
public Sprite LiczbaOczek1;
public Sprite LiczbaOczek2;
public Sprite LiczbaOczek3;
public Sprite LiczbaOczek4;
public Sprite LiczbaOczek5;
public Sprite LiczbaOczek6;
void Awake()
{
n = Random.Range(1, 7);
}
void Start()
{
if (n == 1)
gameObject.GetComponent<Image>().sprite = LiczbaOczek1;
if (n == 2)
gameObject.GetComponent<Image>().sprite = LiczbaOczek2;
if (n == 3)
gameObject.GetComponent<Image>().sprite = LiczbaOczek3;
if (n == 4)
gameObject.GetComponent<Image>().sprite = LiczbaOczek4;
if (n == 5)
gameObject.GetComponent<Image>().sprite = LiczbaOczek5;
if (n == 6)
gameObject.GetComponent<Image>().sprite = LiczbaOczek6;
}![alt text][1]
} and the comparing script:
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class Comparing : MonoBehaviour {
// Use this for initialization
void Start () {
GameObject Image1 = GameObject.Find("Image1");
NewBehaviourScript2sdf Image1Funk = Image1.GetComponent<NewBehaviourScript2sdf>();
GameObject Image2 = GameObject.Find("Image2");
NewBehaviourScript2sdf Image2Funk = Image2.GetComponent<NewBehaviourScript2sdf>();
if (Image1Funk.n < Image2Funk.n)
{
Image1.GetComponent<Image>().color = new Color32(255, 255, 225, 100);
}
if (Image1Funk.n > Image2Funk.n)
{
Image2.GetComponent<Image>().color = new Color32(255, 255, 225, 100);
}
if (Image1Funk.n == Image2Funk.n)
{
Image1.GetComponent<Image>().color = new Color32(0, 0, 225, 100);
Image2.GetComponent<Image>().color = new Color32(0, 0, 225, 100);
}
}
// Update is called once per frame
void Update () {
}
}
would be grateful if someone showed me how to make a script that will work for all the dice at once, so that I later would be able to count the dice which lost in their pairs for both panels. I am new to Unity , so please excuse me for my lack of knowledge.
[1]: /storage/temp/73016-dicescreenshot.png
Your answer
![](https://koobas.hobune.stream/wayback/20220612083741im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Unity Pro vs other engines 1 Answer
Random picture picker 1 Answer
empty GameObject is equal to null on comparison? 1 Answer
Check if Material of a gameObject == a material variable (instance)? 2 Answers
Dice Rolling Detection 1 Answer