示例#1
0
    void Start()
    {
        health         = GetComponent <Health>();
        playerInput    = GetComponent <PlayerInput>();
        playerMovement = GetComponent <PlayerMovement>();
        messenger      = GetComponent <IMessenger>();
        activePowerups = new List <PickupType>();
        Hurtbox bodyHurtbox = GetComponentInChildren <Hurtbox>();

        if (bodyHurtbox != null)
        {
            bodyHurtboxCollider = bodyHurtbox.GetComponent <BoxCollider2D>();
        }
        helmetSpriteRenderer.enabled = false;
    }
示例#2
0
    public void Explode()
    {
        Debug.Log("Boom");

        // find all hurtboxes in radius
        var overlaps = Physics2D.OverlapCircleAll(transform.position, BlastRadius);

        // identify which objects are on the left and right sides
        List <Hurtbox> left  = new List <Hurtbox>();
        List <Hurtbox> right = new List <Hurtbox>();

        foreach (Collider2D overlap in overlaps)
        {
            Hurtbox hurtbox = overlap.GetComponent <Hurtbox>();
            if (overlap.transform.position.x <= transform.position.x)
            {
                if (hurtbox != null && hurtbox.CurrentState != Hurtbox.State.Blocking && !hurtbox.GetComponent <ShieldBlobController>())
                {
                    left.Add(hurtbox);
                }
            }
            else
            {
                if (hurtbox != null && hurtbox.CurrentState != Hurtbox.State.Blocking && !hurtbox.GetComponent <ShieldBlobController>())
                {
                    right.Add(hurtbox);
                }
            }
        }

        // apply knockback and damage to each group of objects
        if (left != null && left.Count > 0)
        {
            foreach (Hurtbox hurtbox in left)
            {
                AttackData.Sign = -1;
                hurtbox.hp.DealDamageNormal(AttackData);
            }
        }
        if (right != null && right.Count > 0)
        {
            foreach (Hurtbox hurtbox in right)
            {
                AttackData.Sign = 1;
                hurtbox.hp.DealDamageNormal(AttackData);
            }
        }

        Instantiate(particles, transform.position, particles.transform.rotation);
        Events.OnExplosion.Invoke();
        Destroy(gameObject);
    }
 public HurtboxBuilder WithRadius(float radius)
 {
     Hurtbox.GetComponent <SphereCollider>().radius = radius;
     return(this);
 }