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(); } } } }
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)); } } }
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(); } }
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); }