Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 /
This question was closed Jan 20, 2012 at 03:40 AM by BlacKatFever for the following reason:

Problem righted itself somehow so it is no longer relevant.

avatar image
0
Question by BlacKatFever · Jan 12, 2012 at 09:56 AM · c#guitexture2d

2D Texture Not Loading

Hey everyone,

Come across sort of a weird problem. I have a scene called "StageSelect" where you can choose which level you'll play. Stages you can select are shown in color and those you haven't unlocked yet are shown in black and white.

I have it set up so that when the scene loads, Unity checks the PlayerPrefs file for an integer (stage0XCheck). Stages that return a value of "0" are locked, "1" are unlocked, and "2~4" represent the various ranks that you can achieve. So the script accesses PlayerPrefs, grabs the int, and then chooses the 2D texture via a switch. The script is fairly long but this is what a piece of it looks like.

 public Texture2D stage01img;
 public Texture2D stage01rank;
 
 public int stage01Check;
 
 void Start()
 {
    StageCheck();
 }
 
 void StageCheck()
 {
   stage01Check = PlayerPrefs.GetInt("stage01");
 
   //stage01
   switch (stage01Check)
   {
     case 1: 
        stage01img = (Texture2D)Resources.Load("st1_select");
        break;
 
     case 4:
        stage01img = (Texture2D)Resources.Load("st1_select");
        stage01rank = (Texture2D)Resources.Load("st_select_grade_a");
        break;
   }

I have everything assigned public so I can see what's going on in the inspector and stage01rank isn't being assigned a texture. If I manually assign an image while the program is running, it appears immediately, otherwise no luck. I've checked the spelling of the file name and all of the images are located in the Resources folder. Debug.Log (and the loaded stage01img texture) are telling me that the program is entering the correct switch statement and running to completion.

Any ideas on what's wrong? I'd understand if it was a problem with my GUI settings but the image itself isn't even loading (as shown by the Stage 01rank = None(Texture2D) in the Inspector. :P

So weird. :P

Comment
Add comment · Show 3
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 syclamoth · Jan 12, 2012 at 10:23 AM 0
Share

I hate to ask a stupid question, but why don't you just do it by assigning textures in the editor?

avatar image BlacKatFever · Jan 13, 2012 at 01:40 AM 0
Share

Not stupid at all.

The reason I don't assign the texture in the editor is that when the scene loads, I have no idea what rank the player will have achieved. For example -

Player 1: Fires up the game for the first time, because he hasn't unlocked any of the stages, only the first stage icon will appear in color - the rest in black and white. Also, none of the "rank" textures (whether the player has earned a "gold", "silver", or "bronze" rating will be visible because he hasn't earned anything yet.)

Player 2: Has managed to unlock all of the stages except stage 5. When the scene loads, the program checks PlayerPrefs and sees what stages he's unlocked and what rank he's earned for each stage. Once the program has that data, it assigns the appropriate texture to the variable. stage01rank = (2DTexture) rankGold or stage01rank = (2DTexture) rankSilver, etc.

Since I have no idea what information will be present in the player's PlayerPrefs file, I don't know which images to assign in the editor.

Unless there is some other, super easy way that I'm overlooking;D

avatar image BlacKatFever · Jan 20, 2012 at 03:39 AM 1
Share

The problem sorted itself (somehow) so I'm closing this question.

Thanks for your time!

0 Replies

  • Sort: 

Follow this Question

Answers Answers and Comments

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

GUI Style Issue-- Texture not changing 2 Answers

Distribute terrain in zones 3 Answers

Multiple Cars not working 1 Answer

My OnGUI() Won't show the Button elements :( 0 Answers

cant get Texture2D.LoadImage() to work 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