What Does GetComponents mean & What does it do?!
What does it mean by GetComponent?
I found out that it means : To access/get other scripts or components in a GameObject or other GameObjects.
But can you please define what it means by this and how you use it (I'm not an English Expert), so please explain as clearly as possible and please answer!
Answer by Priyanka-Rajwanshi · Jul 08, 2018 at 05:26 PM
For example a GameObject has various components of a type(let's say HingeJoint) And you want to edit a property(let's say useSpring) of all the HingeJoints present on the GameObject. GetComponents would return an array of the required Type you specified (here HingeJoint). You can write:
HingeJoint []hingeJoints = gameobject.GetComponents<HingeJoint>();
foreach (HingeJoint joint in hingeJoints)
joint.useSpring = false;
I hope your doubt would be cleared.
Answer by K97 · Jul 08, 2018 at 05:28 PM
This link may help you. https://docs.unity3d.com/ScriptReference/GameObject.GetComponent.html