Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 rakesh91 · Oct 26, 2011 at 06:57 AM · citytraffic

traffic light help .....

hey guyzz... m creating a project for the childrens who r MR s .. i wnat to teach them , hw to deal with city traffic .....i had created a city for them .. nw am not able to proceed further ... m facing problem in makin traffic simulation... i had designed a traffic light ... but m nt able to make traffic system work .... plz help me ....as m new to unity ....

Hey guys. I'm creating a project for the children who are MRs. I want to teach them how to deal with city traffic. I have created a city for them, now I'm not able to proceed further. I'm facing problems in making traffic simulation. I had to design a traffic light, but I'm not able to make the traffic system work. Please help me as I'm new to Unity.

Comment
Add comment · Show 12
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 CHPedersen · Oct 26, 2011 at 07:03 AM 0
Share

What exactly do you need help with? Be specific. How exactly have you built your city? How does one traverse it? On foot? Bike? By car? What part can't you get working? How to make signals change from red to yellow to green and back again? What code have you written already? What are the errors?

avatar image syclamoth · Oct 26, 2011 at 07:05 AM 0
Share

Did you model a traffic light, and now need somebody to code an entire traffic simulator? Good luck with that.

avatar image save · Oct 26, 2011 at 09:08 AM 3
Share

This is something you do with years experience in coding. Humans can't even handle traffic, how would a simulation created by a human be any different? ;-)

avatar image rakesh91 · Oct 26, 2011 at 04:36 PM 0
Share

my que is How to make signals change from red to yellow to green and back again ? n also m have doubt tat , do i have to write qa code with respect to the model of traffic light or i can rite , to as my wish

avatar image save · Oct 26, 2011 at 04:41 PM 0
Share

I'm sorry I get the first part there where you want to change the light at three steps, but I'm having trouble following the actual question. If it's just one traffic light then make use of yields, swap textures for the lights and turn on/off lightsources.

If it's a cross section with several traffic lights which is connected to cars moving, hire a coder. ;-)

Show more comments

2 Replies

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

Answer by Bunny83 · May 28, 2012 at 12:31 AM

Well this is a very old thread, but someone else revived it so lets face the problem. I guess the OP has solved the problem already (or doesn't need the answer anymore) but since the question is still open I've created a "simple" approach.

One way would be to represent each state of a traffic light by a gameobject. This could be the entire model with different textures in each state or lights atached at the right spots with the right color.

I would create one generic script for each traffic light (so no matter if it has 1, 2 or 3 lights) and one script to control the whole system.

I've created a sample scene with the whole package included. The two scripts are really simple and most things are managed directly in the scene. The actual sequence is created in the editor.

It simulates the sequence red --> red-yellow --> green --> yellow --> red
(that's how the traffic lights works in germany ;) )

If you can't find the package link on the webplayer sample page above, here's again the link to the package

This isn't the best solution (if there is even one that can state it's the best). It has some redundancies in the assets, but it's quite simple and you can create any kind of traffic system without changing the code ;) If this would be a serious project you could add a custom inspector to have a better editor for the sequence, but it works well with the default editor.

Note: The overview is just the whole system duplicated on a seperate layer and the lights turned upwards. The two systems run independently from each other but are in sync, so it's just an eye candy :P

Comment
Add comment · Show 3 · 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 jorjdboss · Jul 23, 2012 at 06:32 AM 0
Share

This does not include the signal for turns at crossroads.

avatar image Bunny83 · Jul 23, 2012 at 10:09 PM 2
Share

Uhmm, this was actually just an example. This is even way too detailed for an example, but yes, sure, you can make a crossroad with 3 lanes each, adding tram-tracks, a seperate bus lane and train-tracks. $$anonymous$$aybe a national park in the center with an helipad or even a small airport.

Yes, that's how a usual crossroad would look like...

avatar image jorjdboss · Jul 27, 2012 at 06:10 AM 0
Share

@Bunny83: Co$$anonymous$$g to the actual traffic simulation, its very difficult to implement. $$anonymous$$aybe you can get away with few vehicles following traffic rules and also doing obstacle avoidance to avoid collision. The problem rises exponentially with increase in traffic. Implementing correct reversing and U turn logic, it can be made better. But overall it would take years to polish it and make it right...

@rakesh91: You's question's headline is about making traffic lights work, but in the description you're talking about traffic simulation. HUGE difference my friend...

avatar image
0

Answer by vianey · Oct 07, 2013 at 04:35 PM

try with this code

 var verde : Light;
 var amarillo : Light;
 var rojo : Light;
 
 
 function Start () 
 {
     Semaforo();
 }
 
 function Update () 
 {
     print(Time.time);
 }
 
 function Semaforo()
 {    
     while(true)
     {
     Apagar();
     yield EncenderVerde();
     yield EncenderAmarillo();
     yield EncenderRojo();
     }
 }
 public function Apagar()
 {
 //verde.light.enabled=false;
 amarillo.light.enabled=false;
 rojo.light.enabled=false;
 }
 
 public function EncenderVerde()
 {
     this.transform.name="semaforoenverde";
     verde.light.enabled=true;
     yield WaitForSeconds(10);
     verde.light.enabled=false;
 }
 
 public function EncenderAmarillo()
 {
     this.transform.name="semaforoenamarillo";
     amarillo.light.enabled=true;
     yield WaitForSeconds(2.5);
     amarillo.light.enabled=false;
     yield WaitForSeconds(.5);
     amarillo.light.enabled=true;
     yield WaitForSeconds(.5);
     amarillo.light.enabled=false;
     yield WaitForSeconds(.5);
     amarillo.light.enabled=true;
     yield WaitForSeconds(.4);
     amarillo.light.enabled=false;
 }
 
 public function EncenderRojo()
 {
     this.transform.name="semaforoenrojo";
     rojo.light.enabled=true;
     yield WaitForSeconds(10);
     rojo.light.enabled=false;
 }
 

for me it worked only you should use two different sequences, using spot light

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

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

9 People are following this question.

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

Related Questions

making a traffic system 2 Answers

city engine 3 Answers

Mesh changing in realtime 1 Answer

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

Help with city building game? 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