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 /
avatar image
0
Question by Tomasay · Sep 05, 2015 at 07:32 AM · triggerlight

flickering lights when player gets near

Hi, I am making a simple horror game in Unity3D and I have no idea how to fix this problem. I have a set of lights on a car, and i want them to flicker and then turn off when a player gets near them. I wrote a very simple script so that when the player enters a trigger they would flicker, but the lights flicker even when the player hasnt entered the trigger. please help

public class FlickeringCarLights : MonoBehaviour {

 public Light light1;
 public Light light2;
 public Light light3;
 public Light light4;
 
 public float minTime = 0.05f;
 public float maxTime = 1.2f;
 
 private float timer;
 
 private bool trigger = false;
 
 
 void start ()
 {
     
     light1 = light1.GetComponent<Light> ();
     light2 = light2.GetComponent<Light> ();
     light3 = light3.GetComponent<Light> ();
     light4 = light4.GetComponent<Light> ();
     
     timer = Random.Range (minTime, maxTime);
     
     
 }
 
 void Update ()
 {
     if (trigger = true) {
         timer -= Time.deltaTime;
         if (timer <= 0) {
         
             light1.enabled = !light1.enabled;
             light2.enabled = !light2.enabled;
             light3.enabled = !light3.enabled;
             light4.enabled = !light4.enabled;
         
         }
     }
     
 }
 
 void OnTriggerEnter (Collider other)
 {

     trigger = true;
         
 }

}

Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by getyour411 · Sep 05, 2015 at 07:34 AM

start should be Start, so it is not getting called.

No filtering on your OnTrigger, so who knows what's triggering it; add something like

 if(other.tag == "Player")
 // do stuff
Comment
Add comment · Show 1 · Share
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 Tomasay · Sep 05, 2015 at 04:41 PM 0
Share

Yes! it works perfectly now! thanks for your help.(Im still a newbie in C#). I should also add that in the if statement I forgot to type == ins$$anonymous$$d of =

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

2 People are following this question.

avatar image avatar image

Related Questions

Using shadows as Triggers? 1 Answer

Light switch trigger 3 Answers

What am i doing wrong? I want to make a raycast acces panel with lights 2 Answers

Can't click gameobject when over another trigger? 1 Answer

How do I loop my light animation is javascript? 1 Answer


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