Ejemplo n.º 1
0
 private void Update()
 {
     if (p1 == null || p2 == null)
     {
         return;
     }
     if (Status == Status.North)
     {
         if (p1.Status == Status.North)
         {
             // Push away
             var dir = PushDirection.normalized;
             var dis = Vector2.Distance(transform.position, p1.transform.position);
             p1.AddForce(dir * Mathf.Clamp(PolarForceAmount / dis, 0, 15));
         }
         else if (p1.Status == Status.South)
         {
             // Pull together
             var dir = -PushDirection.normalized;
             var dis = Vector2.Distance(transform.position, p1.transform.position);
             p1.AddForce(dir * Mathf.Clamp(PolarForceAmount / dis, 0, 15));
         }
         if (p2.Status == Status.North)
         {
             // Push away
             var dir = PushDirection.normalized;
             var dis = Vector2.Distance(transform.position, p2.transform.position);
             p2.AddForce(dir * Mathf.Clamp(PolarForceAmount / dis, 0, 15));
         }
         else if (p2.Status == Status.South)
         {
             // Pull together
             var dir = -PushDirection.normalized;
             var dis = Vector2.Distance(transform.position, p2.transform.position);
             p2.AddForce(dir * Mathf.Clamp(PolarForceAmount / dis, 0, 15));
         }
     }
     else if (Status == Status.South)
     {
         if (p1.Status == Status.South)
         {
             // Push away
             var dir = PushDirection.normalized;
             var dis = Vector2.Distance(transform.position, p1.transform.position);
             p1.AddForce(dir * Mathf.Clamp(PolarForceAmount / dis, 0, 15));
         }
         else if (p1.Status == Status.North)
         {
             // Pull together
             var dir = -PushDirection.normalized;
             var dis = Vector2.Distance(transform.position, p1.transform.position);
             p1.AddForce(dir * Mathf.Clamp(PolarForceAmount / dis, 0, 15));
         }
         if (p2.Status == Status.South)
         {
             // Push away
             var dir = PushDirection.normalized;
             var dis = Vector2.Distance(transform.position, p2.transform.position);
             p2.AddForce(dir * Mathf.Clamp(PolarForceAmount / dis, 0, 15));
         }
         else if (p2.Status == Status.North)
         {
             // Pull together
             var dir = -PushDirection.normalized;
             var dis = Vector2.Distance(transform.position, p2.transform.position);
             p2.AddForce(dir * Mathf.Clamp(PolarForceAmount / dis, 0, 15));
         }
     }
 }