- Home /
get component on prefab in script C#
hey,
i have this code where I create an object via a prefab, and I need to get the rigidbody component of that prefab
my code is looking kind of like this:
public class prefab : MonoBehaviour
{
[SerializeField] private Transform prefa;
}
Comment
Answer by ReneSchleese · Jul 07, 2020 at 08:15 AM
Instantiate the prefab and store the result in a variable. Then call GetComponent() on it.
[SerializeField] private GameObject _original;
...
GameObject prefabClone = Instantiate(_original);
Rigidbody cloneRigidBody = prefabClone.GetComponent<Rigidbody>();
Your answer
Follow this Question
Related Questions
Accessing component of a single prefabs' instance. 0 Answers
get component on prefab in script C# 1 Answer
Distribute terrain in zones 3 Answers
Prefab with component, and attached sub component 1 Answer
Multiple Cars not working 1 Answer