Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 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 /
  • Help Room /
avatar image
0
Question by DroidifyDevs · Jun 23, 2016 at 10:02 PM · c#scripting problemplayerprefsintgeneration

How to automatically generate a new int with a specific name?

Hello!

I need to automatically generate an int with a specific name taken from PlayerPrefs. Here's the idea:

 //create the int
 void CreateInt()
 {
     new int PlayerPrefs.GetString("WhatToNameTheInt");
 }

Obviously that code won't work. I've solved much harder C# issues, but this seemingly simply concept is bugging me...

Thanks for your ideas!

Comment
Add comment · Show 7
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
avatar image Habitablaba · Jun 23, 2016 at 10:10 PM 0
Share

$$anonymous$$y initial thought is: "Why?"
Is the player going to see your code?

avatar image DroidifyDevs Habitablaba · Jun 23, 2016 at 10:58 PM 0
Share

No, the player won't see it. But this is the idea: I'm making a base. The base has many slots. On each slot you can mount an upgrade. Here's what I've done: Detect what slot to upgrade Save data with serializer.

What I need to do is select an upgrade for each slot and save it. I'm thinking of generating an int for each slot, and then saving that. Since I have many slots, it won't be easy to do that manually.

Do you have any ideas? Thanks

avatar image Habitablaba DroidifyDevs · Jun 23, 2016 at 11:07 PM 0
Share

Wouldn't a simple list of upgrades be easier?
Or, if you wanted to make a "slot" something more complicated than just something an upgrade goes in, you could define a slot class and have a list of slots.

Show more comments
Show more comments
avatar image Habitablaba · Jun 24, 2016 at 12:44 AM 0
Share

Have a class, planet, that has some information about a planet, and an object of type PlanetaryBase.
Class PlanetaryBase has some information about bases, and an array of slot objects.
Class slot has some information about slots, and an object for an upgrade.
Class upgrade has some information about upgrades, and is extended by other upgrade types that provide specific upgrade functionality.

Then when you save the planet data, it saves the base data, which saves the slot data... etc.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by DroidifyDevs · Jun 24, 2016 at 05:02 AM

@ChrisAngelMindmapfreak I can't reply to you either :/

I've never used C# dictionaries before... I'll give it a shot as this quick example that Bing gave me seems to be close to what I need:

 using System;
 using System.Collections.Generic;
 
 namespace DictionaryTest {
     public class Solution {
         static void Main(String[] args) {
             Dictionary<string, string> dictionary = new Dictionary<string, string>();
 
             // Add values in different ways
             dictionary.Add("Key1", "Value1");
             dictionary["Key2"] = "Value2";
             
             int size = dictionary.Count;
             string key1Value = dictionary["Key1"];
             string key2Value = dictionary["Key2"];
             bool containsKey3 = dictionary.ContainsKey("Key3");
             
             Console.WriteLine("Dictionary size: " + size);
             Console.WriteLine("Key 1 value: " + key1Value);
             Console.WriteLine("Key 2 value: " + key2Value);
             Console.WriteLine("Does Key3 exist? " + containsKey3);
         }
     }
 }

Hopefully I'll be able to figure this out on my own, thanks!

Comment
Add comment · Share
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

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

179 People are following this question.

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

Related Questions

Can PlayerPrefs be accessed in different scripts - c# 2 Answers

I need help with my script please 1 Answer

Auto Set vs Manual Decrease (How to do both?) 1 Answer

Integer multiplies itself by 3 for seemingly no reason 0 Answers

need help with code please 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