Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
0
Question by sokkasokka · Mar 17, 2017 at 07:15 AM · beginnerfor-loopcompiler

For loop doesn't work after compiling

I have a script that should spawn my falling platforms back into their places if the player dies. This works fine in the editor (and in Unity Remote 5) but after compiling it doesn't work anymore. First I used foreach loops but it didn't work. When I read that there are problems with them I changed my script to use normal for loops but the problem still exists after build. Here are the parts of the code that don't execute after build:

   void Start () {
     platforms = GameObject.FindGameObjectsWithTag ("fallingGround");
     fallingPositions = new Vector2[platforms.Length];
     for (int i = 0; i < platforms.Length; i++) {
         fallingPositions [i] = platforms[i].transform.position;
         Debug.Log(fallingPositions[i]);
     }
 }

 public void playerDied () {
     player.transform.position = spawnPoint.transform.position;
     lifeCount--;
     for (int i = 0; i < platforms.Length; i++) {
         GameObject platform = platforms[i];
         platform.transform.position = fallingPositions [i];
         platform.GetComponent<Rigidbody2D> ().mass = 10000;
         platform.GetComponent<Rigidbody2D> ().gravityScale = 0;
         platform.GetComponent<FallingPlatformScript> ().playerEntered = false;
     }
 }
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 sokkasokka · Mar 17, 2017 at 09:39 AM 0
Share

Forgot to mention that I'm making this game for android.

avatar image Commoble · Mar 17, 2017 at 02:47 PM 0
Share

Can you elaborate on how it doesn't work? What's not happening that should be happening, and what's happening that shouldn't be happening?

I don't see anything obviously wrong in this code, you'll need to show us more code than this.

avatar image sokkasokka Commoble · Mar 17, 2017 at 04:25 PM 0
Share

Sure,

what the code above does is that in Start() it makes an array of the positions of all the falling platforms.

Then when the player dies the PlayerDies() is called and it should return the falling platforms to their starting positions. This doesn't happen in the build version.

As I mentioned that in the editor the script works exactly as intended but after I make a build and run the game in my phone everything else works but the PlayerDies() script.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by sokkasokka · Mar 18, 2017 at 04:14 PM

Solved this by moving following code inside the script in the falling platforms.

for (int i = 0; i < platforms.Length; i++) { GameObject platform = platforms[i]; platform.transform.position = fallingPositions [i]; platform.GetComponent ().mass = 10000; platform.GetComponent ().gravityScale = 0; platform.GetComponent ().playerEntered = false; }

Still wondering why this worked in the editor but not in the build. Code is more elegant now tough.

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

98 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

Related Questions

Freeze on compilation on android unity 1 Answer

Meta files keep disappearing from my projects! 0 Answers

standard Assest 1 Answer

How to substitute one object with another in animation clip 0 Answers

Why is my Unity different than the one in the Beginner Tutorial? 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