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 AmarKalabic · Feb 04, 2015 at 03:24 PM · javascriptvariablescriptingbasicsenum

Variable doesn't output what it should?

I've been making an block game for a while but now I'm stuck. I've problem with enums, which I use to store types of blocks. No matter what I do or change, my "Type" variable of every block is "block 7". It's strange because every block has it's own sprite, but block type is bugged and showing "block 7" for every one of them.

     //for (var object : GameObject in go_list) { // I tried using for loop too, same result
     var go_list = GameObject.FindGameObjectsWithTag("blok");
     var l = go_list.length;
     var i : int = 0;
     //Debug.Log(go_list.length); returns 768, which is okay, since I have 3 chunks, 16x16 = 256; 256x3 = 768 blocks
     while (i <= l) {
     var object = go_list[i];
     i += 1;
     if (object.transform.position.y < world.chunkHeight - 1) {
         type = BlockType.block1;
         object.GetComponent(SpriteRenderer).sprite = Sprite.Create(Resources.Load("Sprites/blocks") as Texture2D, Rect(0, 175, 25, 25), Vector2(0.5, 0.5), 25);
     }
     if (object.transform.position.y >= world.chunkHeight - 1) { //bilo gameObject umjesto object
         if (object.transform.position.y >= world.chunkHeight - world.chunkHeight/2) {
             type = BlockType.block2;
             object.GetComponent(SpriteRenderer).sprite = Sprite.Create(Resources.Load("Sprites/blocks") as Texture2D, Rect(25, 175, 25, 25), Vector2(0.5, 0.5), 25);
         }
     }
     if (object.transform.position.y < world.chunkHeight - world.chunkHeight/2) {
         if (object.transform.position.y >= world.chunkHeight - world.chunkHeight/2 - world.chunkHeight/4) {
             var prob_a : int = Random.Range(1,12);
             if (prob_a == 1) {
                 type = BlockType.block4;
                 object.GetComponent(SpriteRenderer).sprite = Sprite.Create(Resources.Load("Sprites/blocks") as Texture2D, Rect(50, 175, 25, 25), Vector2(0.5, 0.5), 25);
             }
             else if (prob_a == 2) {
                 type = BlockType.block5;
                 object.GetComponent(SpriteRenderer).sprite = Sprite.Create(Resources.Load("Sprites/blocks") as Texture2D, Rect(0, 150, 25, 25), Vector2(0.5, 0.5), 25);                
             }
             else {
                 type = BlockType.block3;
                 object.GetComponent(SpriteRenderer).sprite = Sprite.Create(Resources.Load("Sprites/blocks") as Texture2D, Rect(50, 175, 25, 25), Vector2(0.5, 0.5), 25);
             }
         }
     }
     if (object.transform.position.y < world.chunkHeight - world.chunkHeight/2 - world.chunkHeight/4) {
         if (object.transform.position.y >= world.chunkHeight - world.chunkHeight + 1) {
             var prob_b : int = Random.Range(1,24);
             if (prob_b == 1) {
                 type = BlockType.block6;
                 object.GetComponent(SpriteRenderer).sprite = Sprite.Create(Resources.Load("Sprites/blocks") as Texture2D, Rect(0, 125, 25, 25), Vector2(0.5, 0.5), 25);
             }
             else {
                 type = BlockType.block3;
                 object.GetComponent(SpriteRenderer).sprite = Sprite.Create(Resources.Load("Sprites/blocks") as Texture2D, Rect(50, 175, 25, 25), Vector2(0.5, 0.5), 25);
             }
         }
     }
     if (object.transform.position.y < world.chunkHeight - world.chunkHeight + 1) {
         Debug.Log(object.transform.position.y + " " + world.chunkHeight);
         type = BlockType.block7; //block7 is bottom block
         object.GetComponent(SpriteRenderer).sprite = Sprite.Create(Resources.Load("Sprites/blocks") as Texture2D, Rect(75, 175, 25, 25), Vector2(0.5, 0.5), 25);
     }
   }
 }
 enum BlockType {block1, block2, block3, block4, block5, block6, block7};
 var type : BlockType;

P.S. Block 7 is bottom block and it's rendered and spawned last (which maybe could be source of this problem?).

Thanks in advance!

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

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

2 People are following this question.

avatar image avatar image

Related Questions

Using an enum in a class constructor. 1 Answer

Acces C# via Unityscript 2 Answers

playerID does not exist in current context? 3 Answers

How do I use an enum value as a variable? 3 Answers

null reference exception problem with generic lists in unityscript (i think...) 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