- Home /
Setting a component's values.
Hello! I am having trouble with changing components values within code. Here I have a springjoint being added through code
gameObject.AddComponent<SpringJoint>();
This works perfectly, but I'm confused about how to change its values, like connected body. I have been looking around, but I cannot find anything up to date. Is there anyway to change the connected body through code?
Thank you very much for reading, have a good day!
Answer by Spip5 · Aug 15, 2020 at 11:36 AM
I'd suggest you spend some time doing courses on unity, they usually explain these things, and the logic is the same for most components :).
Rigidbody rb = [YOUR CONNECTED OBJECT];
SpringJoint sJ = gameObject.AddComponent<SpringJoint>();
sJ.connectedBody = rb;
Your answer
Follow this Question
Related Questions
Why isn't AddTorque working on this character? 0 Answers
[Physics] Compensating for Moving/Rotating Terrain 0 Answers
How to add gravity without a rigidbody 2 Answers
Problem with movement 0 Answers
Multiple Cars not working 1 Answer