I've been looking at how to use the SendMessage or Visibility actions to turn lights on and off. Using the Object:SendMessage and trying to turn on a light doesn't work.
Am I right in assuming I'll need a custom script for this? If so, what do I do?
Would it be possible to add a Light:TurnOn/Off action in a future update?
Comments
public class ChangeColor : MonoBehaviour {
public bool RoomLock;
public Color colorA;
public Color colorB;
public float speed;
// public Material colorMaterial;
public float intense;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
RoomLock = GameObject.FindWithTag (Tags.persistentEngine).GetComponent ().GetVarValue (2);
if(RoomLock == true)
{
// TRUE
// Color color = Color.Lerp(colorA, colorB, Mathf.PingPong(Time.time * speed, 1));
//colorMaterial.SetColor("_Color", color);
light.color = Color.Lerp(colorA, colorB, Mathf.PingPong(Time.time * speed, 1));
light.intensity = intense;
}
else
{
// FALSE
light.intensity=0;
}
}
}
but i get the error Assets/Scripts/ChangeColor.cs(19,75): error CS0411: The type arguments for method `UnityEngine.GameObject.GetComponent<T>()' cannot be inferred from the usage. Try specifying the type arguments explicitly
SendMessage Switch(true) has no receiver!
UnityEngine.GameObject:SendMessage(String)
I am using object Send message, Message to Send: custom and Method name Switch(true)
Public class ChangeColor : MonoBehaviour {
private void Switch (bool turnOn)
{
if (GetComponent <Light>())
{
GetComponent <Light>().enabled = turnOn;
}
}
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
}
I've tried both ways via talking to the script by sending message to method Switch(true) and false
and to ignore the script and just use TurnOn and TurnOff as a message to the light object.
in both cases i get either Switch(true) has no receiver or TurnOn has no receiver!
I would appreciate any help @2finger cause it is very crucial to be able to talk to functions and variables from AC to the rest of Unity.