I’m seeing a weird behavior when trying to clone an object. Basically I have a simple cube with a light attached to it. The light is disabled by default. What I wanted to do was, on collision for the box, enable the light and create a new cube to repeat the process. I built the cube and light into a prefab and attached my script which looks like this:
var lightBox : Transform;
private var duped = false;
function OnCollisionEnter(collision : Collision) {
if (!duped) {
var newInstance = Instantiate(lightBox, Vector3 (0, 10, 0), Quaternion.identity);
newInstance.light.color = Color(Random.Range(0.0, 1.0), Random.Range(0.0, 1.0), Random.Range(0.0, 1.0), 1);
duped = true;
}
light.enabled = true;
}
What I’ve found is that if I enable my light before Instantiating the new box (i.e. moving the ‘light.enabled = true’ to be the first line in the method), the new box’s light is enabled immediately. If I enable the light afterwards as shown in the code above, the new box’s light is disabled until it collides (the intended behavior).
Is this a bug or is there a reason why enabling the light on one object would cause the light on the next one to be enabled immediately?