Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
Question by KyleRasmusson · May 20, 2016 at 04:03 PM · c#setactivelights

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.

Comment
Add comment · Show 11
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image FortisVenaliter · May 20, 2016 at 04:10 PM 0
Share

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?

avatar image KyleRasmusson FortisVenaliter · May 20, 2016 at 04:16 PM 0
Share

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.

avatar image FortisVenaliter KyleRasmusson · May 20, 2016 at 04:24 PM 0
Share

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.

Show more comments

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

3 People are following this question.

avatar image avatar image avatar image

Related Questions

URP light 2d normalmap gets disabled on runtime 3 Answers

Regarding SetActive function 1 Answer

Disable Object and Enable by Distance from Player 1 Answer

Unable to reactivate an object that's been deactivated. C# 4 Answers

SetActive delay between code and actual object on the screen 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges