A game about forced loneliness, made by TACStudios
1using System.Collections;
2using System.Collections.Generic;
3using UnityEngine;
4
5
6[ExecuteInEditMode]
7public class SamplesLinkLightToEmissive : MonoBehaviour
8{
9
10 public GameObject emissiveObject;
11 public Light lightToLink;
12 public string emissionColorProperty = "_Emission_Color";
13 public string emissionIntensityProperty ="_Intensity";
14
15 void Update()
16 {
17 if (lightToLink != null && emissiveObject !=null )
18 {
19 var renderer = emissiveObject.GetComponent<MeshRenderer>();
20 var propertyBlock = new MaterialPropertyBlock();
21 renderer.GetPropertyBlock(propertyBlock);
22 propertyBlock.SetColor(emissionColorProperty, lightToLink.color * Mathf.CorrelatedColorTemperatureToRGB(lightToLink.colorTemperature));
23 propertyBlock.SetFloat(emissionIntensityProperty,lightToLink.intensity);
24 renderer.SetPropertyBlock(propertyBlock);
25 }
26 }
27}