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 sandhillceltic · Feb 01, 2014 at 07:56 PM · javascriptfor-looptroubleshootingjavascript-specificfor

For statement stops function?

I am working on a physics building game, and I need to switch to play mode from edit mode. When I switch, I need to disable the sphere colliders on all gameobjects with the tag "probe", and connect all the parts to the fuselage (tagged "fuse"). Here is the script-

 var forces : GameObject[];
 var probes : GameObject[];
 function Update () {
     forces = GameObject.FindGameObjectsWithTag("force");
     probes = GameObject.FindGameObjectsWithTag("probe");
     if(Input.GetKeyDown("l")) {
         Disablescols ();
         Enablephysics ();
         GameObject.FindGameObjectWithTag("fuse").AddComponent(Rigidbody);
     }
 }
 
 
 
 
 function Enablephysics () {
     for(var i = 0; i <= forces.length; i++){
         forces[i].AddComponent(Rigidbody);
         forces[i].AddComponent(HingeJoint);
         forces[i].GetComponent(HingeJoint).connectedBody = GameObject.FindGameObjectWithTag("fuse").rigidbody;
         forces[i].GetComponent(HingeJoint).spring.damper = Mathf.Infinity;
     }
 }
 
 
 
 
 function Disablescols () {
     for(var k = 0; k <= probes.length; k++){
         probes[k].GetComponent(SphereCollider).enabled = false;
     }
 }

The script is executing everything well, except it does not add the rigidbodies and does not add the joints. In short, it is not executing Enablephysics ();. Is Unity stopping the script after the FOR statement in Disablescols () met? Can someone help me?

*Javascript only, duh

*thanks

EDIT

I have fixed the problem, with the help of the people that answered. The Debug.Log was not going through, as it was turned off in the console (I don't know why???). Also, the order in which the functions were being called was wrong. Instead of going

  1. Disablescols

  2. Enablephysics

  3. GameObject.FindGameObjectWithTag("fuse")

It had to go

  1. GameObject.FindGameObjectWithTag("fuse")

  2. Disablescols

  3. Enablephysics

as the enablephysics () function requires a rigidbody to work.

Thanks guys!!

Comment
Add comment · Show 4
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 Benproductions1 · Feb 01, 2014 at 09:25 PM 0
Share

Have you tried debugging this problem?

avatar image sandhillceltic · Feb 01, 2014 at 09:31 PM 0
Share

yes, there are no errors, and i have tested quite a bit with Debug.Log

avatar image Benproductions1 · Feb 02, 2014 at 02:29 AM 0
Share

The only way Enablephysics does not get called, is when Disablescols throws an error (Yes, it's the ONLY way, other than the entirety of Unity crashing)

avatar image adnirjhar · Feb 02, 2014 at 08:56 AM 0
Share

I think you turned off the Error printing in the console by toggling that Error key.

1 Reply

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

Answer by adnirjhar · Feb 01, 2014 at 09:32 PM

I think the code is breaking here ->

for(var k = 0; k <= probes.length; k++)

Because you are checking upto equal. Once the code breaks, it wont continue executing with the right behaviour.

Not sure though. :P

Comment
Add comment · Show 4 · 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
avatar image sandhillceltic · Feb 01, 2014 at 09:49 PM 0
Share

I'm not sure what you mean, could you elaborate?

avatar image adnirjhar · Feb 01, 2014 at 09:58 PM 0
Share

I mean you are supposed to check upto probes.length-1 as you are starting from 0. Shouldn't it be something like ?-

for(var k = 0; k <= probes.length-1; k++)

avatar image Benproductions1 · Feb 02, 2014 at 02:27 AM 0
Share

@adnirjhar which simplifies to just:

 for (var k = 0; k < probes.length; k++)
avatar image adnirjhar · Feb 02, 2014 at 08:50 AM 0
Share

yeah. I put the -1 just for his sake, as he used <= .

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

20 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

Related Questions

For loop not working? 1 Answer

For statement errors? 1 Answer

Collision of Character collider not working? 1 Answer

Why is rigidbody.AddRelativeTorque not working? 1 Answer

How do I reset a for loop variable??? 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