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 golddevrush · Dec 16, 2014 at 07:46 PM · spriteruntime

runtime: script variable not processed as demanded

hi all,

i try to make a candy-crush-like game.

i have make some sprites and design them in 5x5. i have attach them a script that show the sprite name and their "game value" in script property.

when i run, i notice that not all my 5x5 sprites have done the script, they just show 0 value. anyone can help me? here is the code snippet:

public float posisibaris=0; public float posisikolom=0; public int jenisunit=0; public int nilai=0;

 // Use this for initialization
 void Start () {
     BlocksUnitScript gameobj = GetComponent<BlocksUnitScript>();
     posisibaris = gameobj.transform.position.x;
     posisikolom = gameobj.transform.position.y;
     jenisunit = get_jenisunit ();
     nilai = get_nilai ();
 }
 private int get_nilai(){
     int returnvalue = 0;
     switch (jenisunit) {
     case 0 :
         returnvalue=0;
         break;
     case 1 : //berry
         returnvalue=50;
         break;            
     case 2 : //grape
         returnvalue=30;
         break;        
     case 3 : //orange
         returnvalue=45;
         break;
     case 4 : //strawberry
         returnvalue=100;
         break;            
     case 5 : //apple
         returnvalue=75;
         break;        
     case 6 : //melon
         returnvalue=300;
         break;
     case 7 : //pear
         returnvalue=500;
         break;
     default :
         returnvalue=0;
         break;
     } 
     return returnvalue;
 }
 
 private int get_jenisunit(){
     int returnindex = 0;
     SpriteRenderer gameobj_sprite = GetComponentInChildren<SpriteRenderer> ();
     if (GlobalVarScript.mySprites != null ) {
         for (int i=0;i<GlobalVarScript.mySprites.Length; i++){
             if (gameobj_sprite.sprite==GlobalVarScript.mySprites[i]) {
                 returnindex=i+1;
                 break;
             }
         }
     }
     gameobj_sprite = null;
     return returnindex ;
 }

alt text

trouble in unity resized.png (122.3 kB)
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
0
Best Answer

Answer by golddevrush · Jan 03, 2015 at 03:35 PM

i have found the solution. the problem is : i write the function of loading sprite from resources in void start. and the function get_nilai is quicker invoked before the function of loading finished, so not all my sprite got the actual value. when i change the location of the function of loading to void awake, it solve the problem.

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

2 People are following this question.

avatar image avatar image

Related Questions

Help with changing spririterenderer's sprite 2 Answers

is there any 4 or 8 direction script? for sprite maneger 2 0 Answers

how to press 2 sprites to display other 1 sprite? 1 Answer

How do I replace a sprite in script? 2 Answers

Unknown Error. 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