- Home /
How to copy all propeties of a light
Hi all, I'm making a simple script to basically copy the properties of one light on to all others . While i could do
[CODE]
public Light baseLight ; public Light[] LU ; void LightChange() { foreach (Light Lighter in LU){ Lighter.area = baseLight.area ; // for each property print(Lighter.name); //. }
[/CODE]
For each property, I want to know if theirs an easy way to copy every property of a light .
ins$$anonymous$$d of copying every property, why not just duplicate the light directly, with instantiate?
Answer by MachCUBED · Nov 27, 2012 at 05:43 AM
You seem to have had some formatting issues, here's a reformatted version of how I think it should look:
public Light baseLight; public Light[] LU;
void LightChange() { foreach (Light Lighter in LU) { Lighter.area = baseLight.area; // for each property print(Lighter.name); //.
} }
You have two options:
1) List each of the properties manually, from http://docs.unity3d.com/Documentation/ScriptReference/Light.html like so:
foreach (Light lighter in LU) { lighter.type = baseLight.type; lighter.color = baseLight.color; lighter.intensity = baseLight.intensity; ...
// Do not add code to copy positions in 3d space, or anything else that you wish not to copy
}
or you can just set all of them to be equal to baseLight (but this will also sync all of the lights' positions in 3d space, as well as other things that you may not want to sync):
foreach (Light lighter in LU) { lighter = baseLight; }
the first option is more time-consuming, but it can be customized to copy only certain members of the Light class.
MachCUBED
I ended up going with the first approach, thanks for your help
Your answer
Follow this Question
Related Questions
Can not use more variables in array? 1 Answer
Turn all objects in the array to make same thing 0 Answers
Finding a pattern in an array 1 Answer
"For"-Loop only works for final element in array 1 Answer
Array Overflow Problem 1 Answer