I previously had my objects simply turning off (exampleObject.active = false) when turning the objects state to on or off, but now that it is all working, I am looking for something a little more graphically appealing, and acceptable for a game.
I changed the line to this (exampleObject.GetComponent().material.SetFloat(“_EmissionScaleUI”, 0.0f) in order to turn the emission value up or down (to turn a series of lights on or off), but it doesn’t work; no errors but it doesn’t do anything.
To clarify, I am trying to change the Emission “brightness” value expressed as a float on the right of the highlighted section in the image below.
Ref: Unity - Manual: Emission
My full code (entire script) has been posted below, in the hopes someone may be able to spot something wrong I, and the Unity debugger cannot.
It may be a simple syntax issue, or the parameter name may have changed, but I have revieved an error each time I attempt to open the Standard Shader code, so I cannot see for myself.
using UnityEngine;
using System.Collections;
public class Gate : MonoBehaviour
{
public GameObject[] lights;
public Switch[] switches;
private int lightCount;
public int switchCount;
private bool[] switchState;//holds previous state to compare to new/current state
private bool changed;//a state has changed
private int index = 0;
void Awake()
{
switchState = new bool[switchCount];
}
void Start()
{
for (index = 0; index < lights.Length; index++)
{
//lights[index].active = false;
lights [index].GetComponent<Renderer> ().material.SetFloat ("_EmissionScaleUI", 0.0f);
}
}
void Update()
{
//check to see if any switch state has changed
changed = false;
for (index = 0; index < switchCount; index++)
{
if (switches[index].state != switchState[index])
{
changed = true;
switchState[index] = switches[index].state;
break;
}
}
//if a state has changed 'index' will hold which one
if (changed)
{
for (int lightCounter = 0; lightCounter < lights.Length; lightCounter++)
{
if (switches[index].lights[lightCounter] == true)//set in switches therefore act on this item
{
bool lightIsActive = false;
//lights[lightCounter].active = !lights[lightCounter].active;
lightIsActive = !lightIsActive;
//lights[lightCounter].GetComponent<Renderer>().material.SetFloat("_EmissionScaleUI",2.0f) = lights[lightCounter].GetComponent<Renderer>().material.SetFloat("_EmissionScaleUI",0.0f);
if (lightIsActive) {
lights [lightCounter].GetComponent<Renderer> ().material.SetFloat ("_EmissionScaleUI", 2.0f);
}
else if (!lightIsActive)
{
lights [lightCounter].GetComponent<Renderer> ().material.SetFloat ("_EmissionScaleUI", 0.0f);
}
}
}
}
}
}