- Home /
Instance variable
I am Making a Car Parking Game . I raycast downward from cubes placed on four corners of Car when all cubes ray touches Parking collider car is parked . I have the same script of raycast downward on all instances of cube . and variable ParkingCollided when false for all cubes and static variable count == 4 then car parked. Now I want two Parking points and want to make ParkingCollided true for all intances again so that the car parked again on Next point how can i make ParkingCollided true for all instances.
public RaycastHit hit; bool ParkingCollided = true
if (Physics.Raycast (transform.position, -Vector3.up, out hit)) {
Debug.DrawLine (transform.position, hit.point, Color.cyan);
if (hit.collider.gameObject.tag == "ParkingPoint") {
if (ParkingCollided) {
ParkingCollided = false;
StaticVariables.ParkingCollisionCount += 1;
if (StaticVariables.ParkingCollisionCount == 4) {
GameObject.FindGameObjectWithTag ("Player").SendMessage ("CarParking");
}
}
}
}
Your answer
![](https://koobas.hobune.stream/wayback/20220612120619im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Move a GameObject using Raycasting Hit position 1 Answer
What's wrong with this script? 2 Answers
Smarter Enemy (take cover(SIMPLE)) 3 Answers
raycasting performance wise 1 Answer
Bullets, raycasts, and obstacles 1 Answer