Hi - I’m new to unity. Anyone have a good example of how to adjust the detonator unity extension variables with javascript? I just have a basic example set up - sphere falls on plane and explodes.
Sphere has a script that instantiates the explosion on collision:
var explosion : Transform;
function OnCollisionEnter () {
Destroy (gameObject);
var explosionInstance : Transform;
explosionInstance = Instantiate(explosion,transform.position, transform.rotation);
}
Explosion is a prefab which contains the detonator-simple prefab. I want to be able to modify the predefined variables of the Detonator script like Duration,Detail,DestroyTime,Size. The simplest example should do fine. Thanks!
EDITED: I adapted the answer to your script. Now it will find a script called Detonator attached to the explosion clone and let a reference in scriptRef, which you will use to modify the Detonator variables. It should work, but you may have problems if some of these variables are used in the Awake function of Detonator.js - as far as I know, Awake is executed during instantiation, thus before your script can modify anything (I believe Start will be executed only right before the next frame, so the modifications will take effect).
var explosion : Transform;
function OnCollisionEnter () {
Destroy (gameObject);
var explosionInstance : Transform;
explosionInstance = Instantiate(explosion,transform.position, transform.rotation);
var scriptRef: Detonator = explosionInstance.GetComponent(Detonator);
scriptRef.Duration = ...; // modify variables using scriptRef
}