Created
February 19, 2015 11:37
-
-
Save david-hodgetts/b7c46ea4fdcf9099f806 to your computer and use it in GitHub Desktop.
scale light range with parent transform on runtime
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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