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 reinholdsberzins · May 28, 2016 at 03:31 PM · components

How in C# do I change value on two same type components, each different value.

Hi guys, I have one GameObjec, to it I have attached two SpringJoints. In code I want to change each SpringJoints Vector3 position like this:

 riderTorso.GetComponent<SpringJoint> ().connectedAnchor = new Vector3 (-0.112f, 0.2f, 0f);

This changes the value of the first SpringJoint attached to this object. I read about the GetComponents(type:SpringJoint) function however I do not understand how to further differentiate each SpringJoint and add unique values (or code) to each.

Sorry if it's retarded question, and I did rtfm but didn't find any example where I could differentiate and apply unique code to each SpringJoint.

Cheers!

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 reinholdsberzins · May 28, 2016 at 07:26 PM 0
Share

Thanks $$anonymous$$mmpies, But by that I still need to drag in the object, and when I drag in the GameObject it takes the first SpringJoint every time. :( alt text

I can drag in just the spring joint component, can I? Because I can't have two inspector views. Am I missing some something?

Thanks a lot for quick answer!

screen-shot-2016-05-28-at-222427.png (6.8 kB)
avatar image reinholdsberzins reinholdsberzins · May 28, 2016 at 07:29 PM 0
Share

Got it... I just needed to have a script on the actual GameObjects the springs are attached to and now I can see the custom variables + the spring joints them selves! Thank you $$anonymous$$mmpies, AWESO$$anonymous$$E! Hour long struggle is over!

avatar image Mmmpies reinholdsberzins · May 28, 2016 at 07:35 PM 1
Share

Glad you got it sorted :)

EDIT - incidentally it's just one way of doing it. You could also have added a unique tag or name to them. There's always lots of ways of cracking a particular program$$anonymous$$g nut in Unity.

1 Reply

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

Answer by Mmmpies · May 28, 2016 at 04:26 PM

Just create 2 public SpringJoints in the script. When you look at the object the script is attached to in the inspector you'll see the SpringJoint entries with a slot next to them, just drag one Springjoint on the first one and the other on the second and you now have a reference to each one. Call them what you want but in this example I call them SJ1 and SJ2.

     public SpringJoint SJ1;
     public SpringJoint SJ2;

Then your code for altering one of them is this...

 SJ1.connectedAnchor = new Vector3 (-0.112f, 0.2f, 0f);

Unity's great for these kind of shortcuts. :D

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

58 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

Related Questions

Is it possible to leave a comment on components like prefabs? 1 Answer

Use c# "ref" with a GameObject or Component 1 Answer

How to get component value without using GetComponent() and Update()/FixedUpdate()? 1 Answer

do something every time a Sprite is added to the Scene 1 Answer

Animation clip not playing but still affecting components of other clips 0 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