Hi,
i am making a project which teaches all the traffic rules to the one who is driving a car, can any one please help me and tell me that how can i show message on screen when a driver reaches at a traffic signal. i.e message “stop” is displayed on screen when driver arrives at “stop” traffic signal
To detect if the car is near the traffic light use a collider. Use OnGUI functions to display a message on screen.
Heres my code…i have used box colliders and GUI function… but the problem with box collider is that your car stops after hitting the collider and message on the screen also doesnt fade away after any specified time.
var msg = false;
function OnCollisionEnter(theCollision : Collision){
if(theCollision.gameObject.name == "trafficLight"){
Debug.Log("collided");
msg=true;
}
}
function OnGUI () {
if (msg== true) {
GUI.Box (Rect (100,0,500,50), "You need to stop if the traffic signal is red");
}
}
You can change the color of the text using:
What you will probably do is change the alpha component of the color from 1.0 down to 0.0 over time.