Ejemplo n.º 1
0
 //When the Seeker collides with another physics object, if that object has the Player tag it injures the target and destroys itself.
 //Uses IVulnerable mechanics
 void OnTriggerEnter2D(Collider2D other)
 {
     if (other.gameObject.tag == "Player")
     {
         IVulnerable target = other.GetComponent("IVulnerable") as IVulnerable;
         target.Injure(damage);
         Kill();
     }
 }
    //OnTriggerEnter2D
    //Handles collision event, checking for a valid collision
    //Only interacts with specified target type. Used IVulnerable and ISpeedMod for effects.
    //Effect depends on chosen Effect enum.
    //Will destroy the missile after impact if destroyOnImpact is true.
    void OnTriggerEnter2D(Collider2D other)
    {
        if (other.gameObject.tag == hitTag)
        {
            //Applies effect based on selected effect type.
            //Note: Incompatable effects (hitting a non-ISpeedMod target with a slow) will still trigger here, but will fail.
            switch (effect)
            {
            case EffectType.None:
                Debug.Log("Hit " + other);
                break;

            case EffectType.Damage:
                IVulnerable damageTarget = other.GetComponent("IVulnerable") as IVulnerable;
                damageTarget.Injure(effectAmount);
                break;

            case EffectType.Slow:
                ISpeedMod speedTarget = other.GetComponent("ISpeedMod") as ISpeedMod;
                speedTarget.SpeedDecrease(effectAmount);
                break;

            default:
                Debug.Log("Effeect not found " + effect);
                break;
            }

            //Destroys the target if set to destroyOnImpact. Otherwise projectile will destroy after missileLifespan.
            if (destroyedOnImpact == true)
            {
                Destroy(gameObject);
                if (deathEmission != null)
                {
                    Instantiate(deathEmission, transform.position, transform.rotation);
                }
            }
        }
    }