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 radkappe · Apr 14, 2015 at 11:07 PM · rigidbodyarrayvariable

Store Rigidbodies in Array

Hi, I am storing the rigidbodies of three gameobjects in three variables.

 var ki1 : Rigidbody;
 var ki2 : Rigidbody;
 var ki3 : Rigidbody;

I assigned them on the editor. After that, I stored the variable names in an Array (ki1, ki2, ki3).

I shuffel them and go through that array. But when I try to put an Addforce to them (like: array[i].AddForce(3000.0, 0.0f, 0.0f);) unity tells me "'AddForce' is not a member of 'Object'".

I do understand the problem as "ki1, ki2 and ki3" are just strings. How do I workaround that? I am not really sure how to achieve that. Isn't it possible to just store the variables in an array and call its items by its variable name?

Thank you

Comment
Add comment · Show 1
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 Eric5h5 · Apr 14, 2015 at 11:31 PM 1
Share

Sounds like you're using JS Arrays; don't ever do that. Only use built-in arrays or generic Lists. But as instruct9r says, you can bypass all this just by using a built-in array directly in the first place. When using arrays, there's no reason to use separate variables at all.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by instruct9r · Apr 14, 2015 at 11:26 PM

mm.. Why don't you just make

 var kiRBs : RigidBody[]

which will make array, for rigidBodies and then use that to loop through it and AddForce...

You don't show how do you assign these rigidbodies in the array, so we can't help you otherwise. Maybe it'll be better to show your whole code so we can see where is 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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

UnityEngine.Rigidbody does not contain a definition for `contraints' 1 Answer

Create new variable name based on array index 3 Answers

How can I make variables reset when leaving play mode? 3 Answers

Creating A Class Variable That Works With Any Class 0 Answers

Make an array with different variables... 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