Lights not turning on or off when being called.
I have a power box that's supposed to be turned off when the player walks up to it and interacts with it, and how I plan on communicating this to the player is an audio and visual cue, with a certain sound playing, and the lights changing from green to red.
public GameObject Green; //My green light
public GameObject Red; //My red light
private AudioSource Electric; //Audio source
private bool DoOnce; //bool that stops the action from being repeated
// Use this for initialization
void Start ()
{
DoOnce = false;
Electric = GetComponent<AudioSource>(); //Gets the audiosource
}
public void Fuse() //function that gets called
{
if(DoOnce == false) //checks for the DoOnce bool, stops the sound and action from repeating
{
print("Is Playing");
Red.SetActive(true); //turns the red light on
Green.SetActive(false); //turns the green light off
Electric.Play(); //Plays the audio side of the interaction
DoOnce = true;
print("DoOnce = " + DoOnce); //Verifies that the action wont be repeated
}
}
So that's where the action is supposed to happen, and pieces of this code do in fact run. For instance I can see in the console that my bool is now set to true, and I hear the audio playing, but the lights don't change. (They are set to Realtime lights, I also tried this by changing the light color using something like Light.color = Color.red; and that itself worked, though only when placed under Void Start()
public class KM_FuseCol : Damage { //replaced monobehaviour with damage
public GameObject[] Turrets; //Turrets to send damage to
private KM_TurretControl Control; //Calling to the Control Script
void OnTriggerEnter(Collider col)
{
if ((col.gameObject.tag == "Phys") && (col.gameObject.name != "GravityGun")) //Checks for interactions
{
foreach (GameObject Turret in Turrets)
{
Turret.SendMessage("ApplyDamage", baseDamage, SendMessageOptions.DontRequireReceiver); //send damage
Control.Fuse(); //Calls to the feedback in the Control Script
print("Called Play"); //Prints to verify the code has run
}
}
}
void Start()
{
Control = GameObject.FindObjectOfType<KM_TurretControl>(); //Allows access to control script.
}
}
Here's the script itself that is calling to this, in case that helps any. Why not just simplify it down to one piece of code? There are multiple different ways to interact with this object, and it honestly just wouldn't work.
Hmmmm.... looks like it should work to me... Are you sure you set the references to your lights correctly in the inspector? And, the Damage class does derive from $$anonymous$$onoBehaviour, right?
I made sure to check that the lights are the correct ones in the inspector, so I know that they are at least the lights that should be in there, and the damage class derives from monobehaviour.
Then I'm stumped. The only reason I can think of for that code to fail would be if the Red and Green were pointing to the same object.