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

· 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

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

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

Internal collisions 1 Answer

Mesh collide, terrain & object 1 Answer

My tank will flips on the air when it collide other objects. 1 Answer

Problem with wheelJoint2D car rotations - my car needs to be able to do double jumps and mid-air rotations. 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