Пример #1
0
 void Update()
 {
     if (thrower == null)
     {
         thrower = FindPlayer();
     }
     if (source.GetThrower() != null && !hotness.GetIsHot())
     {
         source.SetThrower(null);
     }
     if (returning)
     {
         rigid.velocity = (thrower.transform.position - this.transform.position).normalized * (speedBoost);
         if (Mathf.Abs(Vector3.Distance(thrower.transform.position, this.transform.position)) < 1f)
         {
             Destroy(this.gameObject);
         }
     }
     else
     {
         if (thrower == null)
         {
             thrower = FindPlayer();
         }
         if (thrower != null && Mathf.Abs(Vector2.Distance(thrower.transform.position, this.transform.position)) > maxDistance)
         {
             returning = true;
         }
     }
 }
 void CheckForCollision(ParticleSystem.Particle particle)
 {
     foreach (GameObject player in PlayerManager.inst.players)
     {
         if (player.activeSelf && player.GetComponent <PlayerData>() != ballSource.GetThrower())
         {
             if (particle.remainingLifetime >= 2.5 && Vector2.Distance(player.transform.position, particle.position) < .5)
             {
                 player.GetComponent <PlayerDaze>().Daze();
             }
         }
     }
 }
Пример #3
0
 void OnCollisionEnter2D(Collision2D coll)
 {
     if (hotness.GetIsHot())
     {
         if (coll.collider.tag == "Player")
         {
             GameObject particles = Instantiate(particlesPrefab);
             particles.transform.position = transform.position;
             particles.GetComponent <BallParticleSystem>().SetColor(
                 PlayerManager.inst.GetColor(source.GetThrower().num));
         }
     }
 }
Пример #4
0
 void OnCollisionEnter2D(Collision2D other)
 {
     if (isHot &&
         (other.gameObject.tag == "Hittable" ||
          (other.gameObject.tag == "Player" && other.gameObject.GetComponent <PlayerHittable>().GetHittable(source.GetThrower())))
         )
     {
         other.gameObject.GetComponent <Hittable>().Hit(source.GetThrower(), rigid.velocity);
         this.OnHitOther(other.gameObject);
     }
     else
     {
         HitAnything();
     }
 }
Пример #5
0
    GameObject FindClosestPlayer()
    {
        GameObject closestPlayer    = null;
        float      shortestDistance = float.MaxValue;

        foreach (GameObject player in PlayerManager.inst.players)
        {
            if (player.activeSelf)
            {
                float thisDistance = DistanceToPlayer(player);
                if (closestPlayer == null || thisDistance < shortestDistance)
                {
                    if (ballSource.GetThrower() == player.GetComponent <PlayerData>())
                    {
                        continue;
                    }
                    closestPlayer    = player;
                    shortestDistance = thisDistance;
                }
            }
        }
        return(closestPlayer);
    }