Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 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 /
avatar image
0
Question by SalDaDoor · Jun 20, 2021 at 08:24 AM · uistringbooleanlevel select

Level Selection and Strange Error

I followed this great tutorial video on level selection that doesn't let you move forward unless you have at least 1 out of 3 stars and it also keeps track of these stars. Sadly the code simply isn't working.

The error I keep getting is this

FormatException: Input string was not in a correct format.

System.Number.StringToNumber (System.String str, System.Globalization.NumberStyles options, System.Number+NumberBuffer& number, System.Globalization.NumberFormatInfo info, System.Boolean parseDecimal) (at :0)

System.Number.ParseInt32 (System.String s, System.Globalization.NumberStyles style, System.Globalization.NumberFormatInfo info) (at :0)

System.Int32.Parse (System.String s) (at :0)

LevelSelection.UpdateLevelStatus () (at Assets/Scripts/LevelSelection.cs:23)

LevelSelection.Update () (at Assets/Scripts/LevelSelection.cs:18)

Here's the code, thank you to anyone who can help.

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 using UnityEngine.UI;
 using UnityEngine.SceneManagement;
 
 public class LevelSelection : MonoBehaviour
 {
     [SerializeField] private bool unlocked;
     public Image unlockImage;
     public GameObject[] stars;
 
     public Sprite starSprite;
 
     private void Update()
     {
         UpdateLevelImage();
         UpdateLevelStatus();
     }
 
     private void UpdateLevelStatus()
     {
         int previousLevelNum = int.Parse(gameObject.name) - 1;
         if (PlayerPrefs.GetInt("lv" + previousLevelNum.ToString()) > 0)
         {
             unlocked = true;
         }
     }
 
     private void UpdateLevelImage()
     {
         if(!unlocked)
         {
             unlockImage.gameObject.SetActive(true);
             for(int i = 0; i < stars.Length; i++)
             {
                 stars[i].gameObject.SetActive(false);
             }
         }
         else
         {
             unlockImage.gameObject.SetActive(false);
             for(int i = 0; i < stars.Length; i++)
             {
                 stars[i].gameObject.SetActive(true);
             }
         }
     }
 
     public void PressSelection(string _LevelName)
     {
         if(unlocked)
         {
             SceneManager.LoadScene(_LevelName);
         }
     }
 }
 
 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 using UnityEngine.SceneManagement;
 
 public class SingleLevel : MonoBehaviour
 {
     private int currentStarsNum = 0;
     public int levelIndex;
 
     public void BackButton()
     {
         SceneManager.LoadScene("LevelSelection");
     }
 
     public void PressStarsButton(int _starsNum)
     {
         currentStarsNum = _starsNum;
 
         if (currentStarsNum > PlayerPrefs.GetInt("Lv" + levelIndex))
         {
             PlayerPrefs.SetInt("Lv" + levelIndex, _starsNum);
         }
 
         //BackButton();
         //MARKER Each level has saved their own stars number
         //CORE PLayerPrefs.getInt("KEY", "VALUE"); We can use the KEY to find Our VALUE
         Debug.Log(PlayerPrefs.GetInt("Lv" + levelIndex, _starsNum));
 
         BackButton();
     }
 
 }
Comment
Add comment · Show 1
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 xxmariofer · Jun 20, 2021 at 08:56 AM 0
Share

The script Levelselection must be attached to a game object which name is a number, re-watch the tutorial and check where is he attaching the script and what's the name of that object

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

211 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 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

Unity UI: Text Adventure 2 Answers

what the hell is a int? (or a float, or boolean, or string!) 3 Answers

How to activate a panel by a toggle using a script? 1 Answer

Using events to change variables and inherit that value? 0 Answers

How to convert a string to a boolean? 3 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