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 Sottnik · May 29, 2017 at 06:35 AM · c#databasedictionaryvalueselements

How to have Database of Dictionary elements with online images???

Hi guys, I'm new in Unity and I have this kind of problem. I'm doing Android/iOS game similar to Higher Lower Game where you compare 2 elements. My goal is to have databese of elements and when player is online be able to show image attached to element. I want to have 2 modes: when i click first button in first scene, second scene will be loaded and i will compare for example speed of element and when i click second button ,second scene will be loaded but i will compare price of element. I suppose i should use JSON and give my photos to dropbox and somehow shere them to game is this good idea or it's total rubbish? Now i have dictionary with key and 2 values, float and sprite. Part of my GameManager script. Thanks for answers. using System.Collections; using System.Collections.Generic; using UnityEngine; using System.Linq; using UnityEngine.UI; using System; using UnityEngine.SceneManagement;

 public class ListManager : MonoBehaviour {
 public Image carImage1;
     public Image carImage2;
     public Image carImage3;
 
     public Sprite lamborghiniVeneno;
     public Sprite bughattiVeyron;
     public Sprite mcLarenP1;
     public Sprite mcLarenF1;
     public Sprite porscheCarera;
     public Sprite henneseyGT;
 
 private string randomKey1;
     private string randomKey2;
     private string randomKey3;
     private float randomValueSpeed1;
     private float randomValueSpeed2;
     private float randomValueSpeed3;
     private Sprite randomValueImage1;
     private Sprite randomValueImage2;
     private Sprite randomValueImage3;
 
  Dictionary<string,ValueAndSpriteClass> database = new Dictionary<string, ValueAndSpriteClass>();
 
 private class ValueAndSpriteClass
     {
         public float carSpeed { get; set; }
         public Sprite carImage { get; set; }
     }
 public void AddToDatabase()
     {
         database.Add("Lamborghini Veneno",new ValueAndSpriteClass { carSpeed=440,carImage=lamborghiniVeneno});
         database.Add("Bughatti Veyron", new ValueAndSpriteClass { carSpeed = 420, carImage = bughattiVeyron });
         database.Add("Porchce Carera", new ValueAndSpriteClass { carSpeed = 400, carImage = porscheCarera });
         database.Add("Hennesey GT", new ValueAndSpriteClass { carSpeed = 460, carImage = henneseyGT });
         database.Add("MCLaren P1", new ValueAndSpriteClass { carSpeed = 370, carImage = mcLarenP1 });
         database.Add("MCLaren F1", new ValueAndSpriteClass { carSpeed = 430, carImage = mcLarenF1 });
     }
 
 private void ChangeRandomElement1()
     {
         var rnd = new System.Random();
         var randomEntry1 = database.ElementAt(rnd.Next(0, database.Count));
         randomKey1 = randomEntry1.Key;
         randomValueSpeed1 = randomEntry1.Value.carSpeed;
         randomValueImage1 = randomEntry1.Value.carImage;
         database.Remove(randomKey1);
         if (randomKey3 != null)
         {
             database.Add(randomKey3, new ValueAndSpriteClass { carSpeed = randomValueSpeed3, carImage = randomValueImage3 });
         }
         Debug.Log(randomKey1 + randomValueSpeed1);
     }
 
     private void ChangeRandomElement2()
     {
         var rnd = new System.Random();
         var randomEntry2 = database.ElementAt(rnd.Next(0, database.Count));
         randomKey2 = randomEntry2.Key;
         randomValueSpeed2 = randomEntry2.Value.carSpeed;
         randomValueImage2 = randomEntry2.Value.carImage;
         database.Remove(randomKey2);
         if (randomKey1 != null)
         {
             database.Add(randomKey1, new ValueAndSpriteClass { carSpeed = randomValueSpeed1, carImage = randomValueImage1 });
         }
         Debug.Log(randomKey2 + randomValueSpeed2);
     }
 
     private void ChangeRandomElement3()
     {
         var rnd = new System.Random();
         var randomEntry3 = database.ElementAt(rnd.Next(0, database.Count));
         randomKey3 = randomEntry3.Key;
         randomValueSpeed3 = randomEntry3.Value.carSpeed;
         randomValueImage3 = randomEntry3.Value.carImage;
         database.Remove(randomKey3);
         if (randomKey2 != null)
         {
             database.Add(randomKey2, new ValueAndSpriteClass { carSpeed = randomValueSpeed2, carImage = randomValueImage2 });
         }
         Debug.Log(randomKey3 + randomValueSpeed3);
     }
 }
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

6 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Accessing a Class's Variables from within a Dictionary Element 1 Answer

Determine an index of a closest number in a database, from a user's input 1 Answer

Assigning a value to a Dictionary key changes other key values 0 Answers

How do I create a Key and Values Dictionary array in C# 1 Answer

Storing Items in a Building Blueprint 0 Answers


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