Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Valinor111 · Jun 27, 2016 at 02:10 PM · comparisondice

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

dicescreenshot.png (7.3 kB)
Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

3 People are following this question.

avatar image avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges