Legacy Documentation: Version 4.5.0

Script language:

  • JS
  • C#
  • Boo
Script language

Select your preferred scripting language. All code snippets will be displayed in this language.

var range: float;
float range;
range as float

Description

The range of the light.

See Also: Light component.

	// Pulse light's range between original range
	// and half of the original one
	
	var duration : float = 3.0;
	private var originalRange : float;
	originalRange = light.range;
	
	function Update() {
		var amplitude : float = Mathf.PingPong( Time.time, duration );
		// transform from 0..duration to 0.5..1 range
		amplitude = amplitude / duration * 0.5 + 0.5;
		// set light range
		light.range = originalRange * amplitude;
	}
using UnityEngine;
using System.Collections;

public class ExampleClass : MonoBehaviour {
    public float duration = 3.0F;
    private float originalRange;
    void Update() {
        float amplitude = Mathf.PingPong(Time.time, duration);
        amplitude = amplitude / duration * 0.5F + 0.5F;
        light.range = originalRange * amplitude;
    }
    void Example() {
        originalRange = light.range;
    }
}
import UnityEngine
import System.Collections

public class ExampleClass(MonoBehaviour):

	public duration as float = 3.0F

	private originalRange as float

	def Update() as void:
		amplitude as float = Mathf.PingPong(Time.time, duration)
		amplitude = (((amplitude / duration) * 0.5F) + 0.5F)
		light.range = (originalRange * amplitude)

	def Example() as void:
		originalRange = light.range