The simplest method is to make life public and do the following (c#). Get component needs to know the type of component you are accessing. The component must be a monobehavior.
// Used in the method to set the variable
instance.GetComponent<Life>().life = 50;
// The component script
public class Life : MonoBehaviour {
public float life = 0;
}
You will need to adjust this code to call the correct name of your component. You will also need to convert it to JavaScript, the syntax is slightly different.
You can also investigate using a factory pattern, however that’s probably overkill for your situation.