• 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
Question by AlexLundstrom · Apr 15, 2018 at 05:52 PM · collidercarlightssimulationtraffic

How can I make simple traffic lights?

I'm making traffic simulation. I want that if the light is red, the collider appears and the car stops and if the light is green, the collider dissapears. Cars have sensors that can notice if something is in front of it. When the sensor notice something, the car breaks. It works if car in head of the other car slows down, the car in the back will break. It works with the collider too. I just want to know how can I make simple traffic lights. I just need green and red light. Any help is appreciated.

Comment

People who like this

0 Show 1
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 shadowpuppet · Apr 15, 2018 at 07:10 PM 0
Share

sounds like if you were able to code all that other stuff with sensors that this should be a breeze with many possible ways. Are the lights automated with some kind of a timer? You can make the red light collider a child of the red light and just use gameObject.SetActive (true) or (false). But you should probably have a yellow light in there as well?

 public Light lightOn;
 public Light lightOff1;
 public Light lightOff2;
 public int timeOn;
 Void OnEnable(){
 StartCoroutine(DelayBeforLightChange());
 
 private IEnumerator DelayBeforLightChange(){
         yield return new WaitForSeconds(timeOn);
 lightOn.SetActive (true);
 lightOff1.SetActive (false);
 lightOff2.SetActive (false);
 }
 }
 //put this on each of the red yellow and green lights and drag into the public variable for each script the light that will be turning on as well as the two that will be off and set the timeOn to how long you want each light to remain on. the red light collider can be a child of the red light. 



 Or you could go with a timer script and just change the color of a single light with 
 
  public Light lt;
 publiv int timeOn;
     void Start() {
         lt = GetComponent<Light>();
 StartCoroutine( DelayBeforeLightChange());
     }
  private IEnumerator DelayBeforeLightChange(){
         yield return new WaitForSeconds(timeOn);
 
 lt.color = Color.red;
 
         }
 }


0 Replies

  • Sort: 

Unity Answers is in Read-Only mode

Unity Answers content will be migrated to a new Community platform and we are aiming to launch a public beta by June 9. Please note, Unity Answers is now in read-only so we can prepare for the final data migration.

For more information and updates, please read our full announcement thread in the Unity Forum.

Follow this Question

Answers Answers and Comments

92 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Internal collisions 1 Answer

Applying proper drag and center of mass for a vehicle 1 Answer

Use OpenCV with in-game camera to detect road lanes 0 Answers

How to attach a collision mesh (.obj) to a car 1 Answer

Problem with colliders when they get on each other. 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