Пример #1
0
    private void InteractWithTarget()
    {
        if (target != null)
        {
            // If current target is a collectible, call Collect() on it (free for you, cheap for them (tm) )
            Collectible collectible = target.GetComponent <Collectible>();
            if (collectible)
            {
                collectible.CollectIfPossible();
            }

            // If current target is a PlantableZone, water it
            PlantableZone plantableZone = target.GetComponent <PlantableZone>();
            if (plantableZone != null)
            {
                plantableZone.Water();
            }

            // If current target is a Strikable, strike it up
            IStrikeable strikable = target.GetComponent <IStrikeable>();
            if (strikable != null)
            {
                strikable.Strike(this.transform.position, null);
            }
        }

        Destroy(this.gameObject);
    }
    private void HandleCurrentTarget()
    {
        // If current target is a collectible, call Collect() on it (free for you, cheap for them (tm) )
        Collectible collectible = target.GetComponent <Collectible>();

        if (collectible)
        {
            collectible.CollectIfPossible();
        }

        // If current target is a PlantableZone, water it
        PlantableZone plantableZone = target.GetComponent <PlantableZone>();

        if (plantableZone != null)
        {
            plantableZone.Water();
        }

        // If current target is a Strikable, strike it up
        IStrikeable strikable = target.GetComponent <IStrikeable>();

        if (strikable != null)
        {
            strikable.Strike(this.transform.position, null);
        }

        // If we went to water, Fill'r up
        if ((1 << target.layer) == AI.WaterLayermask)
        {
            inventory.FillWaterLevel();
        }
    }
Пример #3
0
    private void HandleWeaponHit(Collider2D other)
    {
        // we can only "hit" something if we're using our weapon, not when it's just sitting idle
        if (usingWeapon)
        {
            // If this is on the enemy layer, give us a little knockback when we hit it.
            // TODO: Figure out how to do "pogo" knockback for swinging downwards later
            if ((1 << other.gameObject.layer == AI.EnemyLayermask) && !hitHistory.HitSomethingAlready())
            {
                // -1 or 1 exclusively in x, 0 on y, depending on position relative to enemy
                Vector2 hKnockback = (player.transform.position - other.transform.position).x < 0f ? Vector2.left : Vector2.right;
                player.GetPushed(hKnockback * 5f, 0.1f);
            }

            IStrikeable strikeable = other.GetComponent <IStrikeable>();
            if (strikeable != null && !hitHistory.HaveHit(other.gameObject))
            {
                strikeable.Strike(this.transform.position, this.weapon);
                hitHistory.MarkObjectAsHit(other.gameObject);
            }
        }
    }