Hi, I need a way to understand in c# when a ray stop hitting an object.
RaycastHit boostHit;
Vector3 bottom = transform.TransformDirection (Vector3.down);
bool prevFinishLane = finishLane;
if (Physics.Raycast (transform.position, bottom, out boostHit)) {
if (boostHit.collider.tag == "Start") {
finishLane = true;
} else {
finishLane = false;
}
if (boostHit.collider.tag == "Boost") {
GetComponent<AudioSource>().PlayOneShot (boostSound);
GameManager.Instance.SetCheckedBoost (GameManager.Instance.GetCheckedBoost () + 1);
Debug.Log ("Boosts: " + GameManager.Instance.GetCheckedBoost ());
if (boostTimer == 0.0F) {
boost = true;
maxSpeed = GameManager.Instance.GetBoost ();
accel = 20.0F;
}
}
// if (boostHit.collider.tag == "Brackes") {
//
// prevSpeed = speed;
//
// GetComponent<AudioSource>().PlayOneShot (brackesSound);
// if (decelTimer == 0.0F) {
// brakeDecel = true;
// decel = 40.0F;
// }
// }
}
else {
finishLane = false;
}
That’s why in this way the boost collider returns a lot of fires. I need that the event returns only one impulse per passage. (Boost). So I thought to detect when tha ray leaves the object instead of when the ray hits the object…
But I can’t code that…