Hey there, I am fairly new to coding and I’ve been trying to create a simple script that can adjust alot of lights while leaving their individual levels intact,
eg.
light1 = 1.0
light2 = .7
light 3 = .1
I’d like to have a variable that can multiply all of them 0 - 1 so if the variable was .5 they would be
light1 = .5
light2 = .35
light 3 = .05
I’m struggling with the syntax and logic of it though.
Anyone know how to do this?
Thanks alot!
You can use an array.
lights = new float[3];
lights[0] = 1.0; // etc.
You can loop through the array and multiply them all by the given value.
–Eric
C#:
using UnityEngine;
using System.Collections;
public class EditLight : MonoBehaviour {
public Light[] l;
public float[] light_values_start;
public float[] light_values_out;
public float multiply_by = 1f;
void Awake() {
light_values_start = new float[l.Length];
light_values_out = new float[l.Length];
}
// Update is called once per frame
void Update () {
for(int i=0; i < l.Length; i++) {
if(light_values_out[i] != (light_values_start[i] * multiply_by)) {
light_values_out[i] = (light_values_start[i] * multiply_by);
l[i].range = light_values_out[i]; // or whatever you need it for
}
}
}
}
wow thanks eTag!
I’m working my way through it now. I just realised that you are using update Function, though I really only need to do it in the editor/non realtime. update would be a waste of cycles eh?
yeah, I just made a custom, demo type script. If you want, I could help you out via Skype if you have it, or you could email me. Both forms of contact you can find on my members page, but it sounds like you (sort of at the least) know what to do from here, so Good Luck! You could put the code into some “ButtonClick” function that triggers when you click on an EditorButton in a custom window, but whatever you want really! Cheers!
Thanks again eTag.
I’ll look into doing what you have said with the custom window/button.