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 /
avatar image
0
Question by Crypton · Jul 23, 2012 at 07:13 PM · texturebuttonresources.loadcustom class

Show images on buttons from an example

Following a Robot Repair example from "Unity 3.x Game Development by Example" book. I have reached a point where I should see whole randomized and pictured layout. (Page 169)

Worked hard and finally solved my issue myself :). For anyone else who might follow the book and run into similar issue this is what I suggest:

1)

Assets/Scripts/sc_GameScript.js(x,x): BCE0048: Type 'Object' does not support slicing.

Under #pragma strict card:Object casting gives you error. So make card:Card to get values from arrays correctly. I dunno why book suggest to do that. Maybe they don't use #pragma strict.

(Perhaps somebody else with more experience can give the reason?)

2)

I completely rewrote the whole card dealing and bulding blocks and saw where was my error. It all stood begind one "/" symbol xD. How typical! Inside Resources.Load I wrtoe "Images/Robots" instead of "Images/Robots*/*"

The important thing here was also that I didn't have the original resources of that example, so I did everything myself and realized I didn't have Resources folder created inside the project tab. When using Resources.Function_name you need to have Resources folder created! I missed that.

Instead of loading image inside Button function, I completely moved it into Card class's constructor function. That way resource isn't loaded on every frame, but instead on Card instance creation!

Relevant parts of the code:

     class Card extends System.Object //Create the class
     {
      var img:Texture; //Create a texture variable
     
      function Card(imgName:String) //The constructor is the very first function that gets called, automatically
      {
                  //This is where I load the image! String of the image name is still the argument.
      img = Resources.Load("Images/Robots/" + imgName);
      }
      
     }
 
 [...]
 
 function BuildGrid()
 {
 var kaart:Card;
 [...]
  for (k=0; k<rows; k++)
  {
    [..]
    for(l=0; l<cols; l++)
    {
     kaart = aGrid[k][l];
     //Here I point to the class variable to get the texture!
  if( GUILayout.Button(kaart.str_img) )//, GUILayout.Width(cardW)) )
  {
  Debug.Log("4. Clicked on " + k + ";" + l);
  }
    }
    [..]
  }     
 [...]
 }
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

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by Crypton · Jul 25, 2012 at 09:08 PM

Hope this works.

I solved my issue and stated the solution in the first post.

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Creating a component from a button click 1 Answer

Change GUI.Button Texture on runtime 1 Answer

gui.button not display text and texture 2 Answers

GUI Texture on Button Swap 3 Answers

Show mouse click feedback on textured 2d plane button 2 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