Browse Source

Rewrite part of script a trigger page for clarity.

* changes longer form of the same thing to a version using the built
in Collision.Ended() method that already exists.
* reformatted bit of code fetching the collider from the collision to
match the sample earlier on the page, also looks nicer cause it doesn't
wrap.
Robin Hübner 6 years ago
parent
commit
4417566343
1 changed files with 5 additions and 15 deletions
  1. 5 15
      en/manual/physics/script-a-trigger.md

+ 5 - 15
en/manual/physics/script-a-trigger.md

@@ -183,13 +183,7 @@ Let's write a script to change the size of the ball when it enters the trigger.
                     otherCollider.Entity.Transform.Scale = new Vector3(2.0f, 2.0f, 2.0f);
 
                     // 2. Wait for the entity to exit the trigger
-                    Collision collision;
-
-                    do
-                    {
-                        collision = await trigger.CollisionEnded();
-                    }
-                    while (collision != firstCollision);
+                    await firstCollision.Ended();
 
                     otherCollider.Entity.Transform.Scale= new Vector3(1.0f, 1.0f, 1.0f);
                 }
@@ -260,19 +254,15 @@ namespace TransformTrigger
                 // 1. Wait for an entity to collide with the trigger
                 var firstCollision = await trigger.NewCollision();
 
-                var otherCollider = trigger == firstCollision.ColliderA ? firstCollision.ColliderB : firstCollision.ColliderA;
+                var otherCollider = trigger == firstCollision.ColliderA
+                    ? firstCollision.ColliderB
+                    : firstCollision.ColliderA;
                     
                 // 2. Change the material on the entity
                 otherCollider.Entity.Get<ModelComponent>().Materials[0] = material2;
                 
                 // 3. Wait for the entity to exit the trigger
-                Collision collision;
-
-                do
-                {
-                    collision = await trigger.CollisionEnded();
-                }
-                while (collision != firstCollision);
+                await firstCollision.Ended();
 
                 // 4. Change the material back to the original one
                 otherCollider.Entity.Get<ModelComponent>().Materials[0] = material1;