I made a prefab gameObject with a rigidbody component attached. Whenever I change the mass of the original prefab from the inspector, all the instances present in the scene get affected (the field is not overridden). But when I try to do the same thing using a script, the mass of the instances remain unchanged (only the main prefab is affected and every time I enter play mode, it retains its previous value!).
The script is attached to another gameObject and looks like this:
public class CubeScript : MonoBehaviour {
public GameObject largeCube; // dragged the original prefab in the inspector
private Rigidbody rb;
// Use this for initialization
void Start ()
{
rb = (Rigidbody) largeCube.GetComponent ("Rigidbody");
rb.mass = 44; // this is not changing the instances, rather only the main prefab. Note that the mass is not overridden
}
}
I don’t understand as a beginner. The tutorials say that it is the same whether you change something from the inspector or using a script like that. Please explain this to me.