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;
}
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;
}
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>();