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 njwashaiful · Nov 04, 2018 at 01:57 AM · animationunity 5avatartraffic

Making character respond to traffic light

I'm trying to build a traffic scene in the unity. i have an avatar as pedestrian and it walks along the sidewalk & uses the pedestrian crossing to cross the road. However, i also want the pedestrian to respond to the traffic light so that it wont cross the road when there's a red light. is there any script that i need to write or is there any built in component in the unity engine that could make an object respond to another object? Im still new to this engine & kind of not know where to start. Help me please! thank you!

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

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by zxc76_die · Nov 04, 2018 at 04:27 AM

Create an invisible cube at a pedestrian crossing. Make him a colider trigger. And add this object through the inspector in the object of the traffic light. GameObject MyTrafficColiderObject;

From the traffic light send the variable "bool stand" to this invisible cube.

Through OnTriggerStay, give the pedestrian information that you cannot go ("bool stop = false")

Like that. Sorry for translation difficulties. :)

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
avatar image
0

Answer by njwashaiful · Nov 04, 2018 at 06:56 PM

Thank you @zxc76_die for the reply! ok, ive created a cube and added it in front of the cross road. however i couldnt seem to add this object to the traffic light object. this is the script of the traffic light: using UnityEngine; using System.Collections;

 //=============================================================================
 //  HaloTrafficLight
 //  by Healthbar Games (http://healthbargames.pl)
 //  author: Mariusz Skowroński
 //
 //  Simple implementation of TrafficLight
 //  For each of three light colors (red, yellow and green) it uses
 //  one mesh renderer and one object with halo effect attached.
 //  To visualize the states of lights (on / off) it requires two materials:
 //  - one with a texture for the lights turned off
 //  - and one with a texture for the lights turned on.
 //  You can use (like in demo scene) two different materials with single,
 //  common texture for light states.
 //=============================================================================
 
 namespace HealthbarGames
 {
     public class HaloTrafficLight : TrafficLightBase
     {
         public Renderer RedRenderer;
         public GameObject RedHalo;
 
         public Renderer YellowRenderer;
         public GameObject YellowHalo;
 
         public Renderer GreenRenderer;
         public GameObject GreenHalo;
 
         public Material LightsOnMat;
         public Material LightsOffMat;
 
         private bool mInitialized = false;
 
         void Awake()
         {
             if (    (RedRenderer != null || RedHalo != null)
                 &&  (YellowRenderer != null || YellowHalo != null)
                 &&  (GreenRenderer != null || GreenHalo != null)
                 )
             {
                 mInitialized = true;
             }
             else
             {
                 mInitialized = false;
                 Debug.LogError("Some variables haven't been assigned correctly for HaloTrafficLight script.", this);
             }
         }
 
         // implementation of the callback from TrafficLight - called when lights state has changed
         public override void OnLightStateChanged(bool redLightState, bool yellowLightState, bool greenLightState)
         {
             if (!mInitialized)
                 return;
             if (RedHalo != null)
                 RedHalo.SetActive(redLightState);
 
             if (RedRenderer != null)
                 RedRenderer.material = (redLightState) ? LightsOnMat : LightsOffMat;
 
             if (YellowHalo != null)
                 YellowHalo.SetActive(yellowLightState);
 
             if (YellowRenderer != null)
                 YellowRenderer.material = (yellowLightState) ? LightsOnMat : LightsOffMat;
 
             if (GreenHalo != null)
                 GreenHalo.SetActive(greenLightState);
 
             if (GreenRenderer != null)
                 GreenRenderer.material = (greenLightState) ? LightsOnMat : LightsOffMat;
         }
     }
 }
 

so if i add public GameObject TrafficLightCollider; , how do i send the variable bool stand to this collider?

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

316 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 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 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 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

i have problem with animation play via script 3 Answers

Android cannot play unity app 1 Answer

How to create cutscene to be started in the middle of game? 1 Answer

why is mecanim not seeing all of my bones ? 1 Answer

Issue with mecanim playing an animation using setbool 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