Forráskód Böngészése

Bugfix multiple wheel clones at spawn/despawn

Marcel Zickler 2 éve
szülő
commit
57d83c3253
1 módosított fájl, 7 hozzáadás és 5 törlés
  1. 7 5
      Assets/Scripts/TrafficSimulation/WheelDrive.cs

+ 7 - 5
Assets/Scripts/TrafficSimulation/WheelDrive.cs

@@ -61,20 +61,22 @@ namespace TrafficSimulation{
         private WheelCollider[] wheels;
         private float currentSteering = 0f;
 
-        void OnEnable(){
+        private void Start()
+        {
             wheels = GetComponentsInChildren<WheelCollider>();
 
-            for (int i = 0; i < wheels.Length; ++i) 
+            for (int i = 0; i < wheels.Length; ++i)
             {
-                var wheel = wheels [i];
+                var wheel = wheels[i];
 
                 // Create wheel shapes only when needed.
                 if (leftWheelShape != null && wheel.transform.localPosition.x < 0)
                 {
-                    var ws = Instantiate (leftWheelShape);
+                    var ws = Instantiate(leftWheelShape);
                     ws.transform.parent = wheel.transform;
                 }
-                else if(rightWheelShape != null && wheel.transform.localPosition.x > 0){
+                else if (rightWheelShape != null && wheel.transform.localPosition.x > 0)
+                {
                     var ws = Instantiate(rightWheelShape);
                     ws.transform.parent = wheel.transform;
                 }