private void OnCollisionEnter2D(Collision2D collision) { GameObject collider = collision.collider.gameObject; PotionEffectsScript pe = collider.GetComponent <PotionEffectsScript>(); if (pe != null) { switch (Type) { case PotionEffect.Agility: pe.ApplyAgility(Duration); break; case PotionEffect.Burning: pe.ApplyBurning(Duration); break; case PotionEffect.Frozen: pe.ApplyFrozen(Duration); break; case PotionEffect.Poison: pe.ApplyPoison(Duration); break; case PotionEffect.Strength: pe.ApplyStrength(Duration); break; } this.gameObject.SetActive(false); } }
// Update is called once per frame void Update() { Collider2D[] colliders = Physics2D.OverlapBoxAll(new Vector2(gameObject.transform.position.x, gameObject.transform.position.y), new Vector2(collider.bounds.size.x / 2, collider.bounds.size.y / 2), AffectedLayer); for (int i = 0; i < colliders.Length; i++) { if ((AffectedLayer.value & (1 << colliders[i].gameObject.layer)) > 0) { PotionEffectsScript pe = colliders[i].GetComponent <PotionEffectsScript>(); if (pe != null) { switch (Type) { case PotionEffect.Agility: pe.ApplyAgility(Duration); break; case PotionEffect.Burning: pe.ApplyBurning(Duration); break; case PotionEffect.Frozen: pe.ApplyFrozen(Duration); break; case PotionEffect.Poison: pe.ApplyPoison(Duration); break; case PotionEffect.Strength: pe.ApplyStrength(Duration); break; } this.gameObject.SetActive(false); } } } }
public override void OnFreeze() => pes.ApplyFrozen(3);