Skip to content

Instantly share code, notes, and snippets.

@david-hodgetts
Created February 19, 2015 11:37
Show Gist options
  • Save david-hodgetts/b7c46ea4fdcf9099f806 to your computer and use it in GitHub Desktop.
Save david-hodgetts/b7c46ea4fdcf9099f806 to your computer and use it in GitHub Desktop.
scale light range with parent transform on runtime
using UnityEngine;
using System.Collections;
public class ScaleLightRange : MonoBehaviour {
Light _light;
float _onAwakeRange;
float _onAwakeScaleFactor;
void Awake () {
_light = GetComponent<Light>();
_onAwakeRange = _light.range;
_onAwakeScaleFactor = transform.lossyScale.magnitude;
}
void Update () {
var ratio = transform.lossyScale.magnitude / _onAwakeScaleFactor;
_light.range = _onAwakeRange * ratio;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment