- Home /
Car wont drive again after red light
I'm trying to make a red light green light game and i made a couple of very basic scripts that make a car drive forward then stop if light is red.
This is my light script
var ligght = false;
var target = Car;
function Update() {
if(Input.GetMouseButtonDown(0))
ligght = true;
if(Input.GetMouseButtonDown(1))
ligght = false;
}
function OnTriggerEnter(other : Collider){
if(ligght == false){
target.speed = 0;
}
if(ligght == true){
target.speed == 60;
}
}
This is my car script
#pragma strict
static var speed = 50;
var crash = false;
function Start (){
rigidbody.collisionDetectionMode = CollisionDetectionMode.ContinuousDynamic;
}
function Update (){
transform.position.z += speed * Time.deltaTime;
if(crash == true){
speed -= Time.deltaTime;
}
}
function OnTriggerEnter(other : Collider){
if(other.gameObject.name == "CarX"){
crash = true;
}
}
Can you guys find the problem?
Comment
OnTriggerEnter only happens when the collision first occurs. To check if the trigger is still colliding, use OnTriggerStay : http://docs.unity3d.com/Documentation/ScriptReference/Collider.OnTriggerStay.html
Use OnTriggerStay in your Traffic Light script =]
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
I made a better shader how do i fix[add _Shadow Strength]help???>Sorry that im asking for to much 1 Answer
Camera follows not right 0 Answers
photocamera flash 1 Answer
How to make flary light reflection 1 Answer