public void RetractInstantly()
        {
            Deactivate();
            transform.position = sheath.transform.position;
            sheath.PutBackKnife(this);
            if (stuckOn != null)
            {
                Vector2 force = Vector2.zero;
                stuckOn.Remove(this.gameObject);
            }
            stuckOn     = null;
            stuckAttack = null;

            Stuck            = false;
            hoverTimer       = 0;
            traveledDistance = 0;
            State            = KnifeState.InSheath;

            if (flyingVFX)
            {
                List <ParticleSystem> particles = new List <ParticleSystem>();
                flyingVFX.GetComponentsInChildren(particles);
                flyingVFX.SetParent(null);
                foreach (var particle in particles)
                {
                    particle.Stop();
                }
            }

            if (chargeFlyingEffect)
            {
                chargeFlyingEffect.StopDraw();
            }
        }
Ejemplo n.º 2
0
    private void Returning()
    {
        var dir = sheath.transform.position - transform.position;

        if (dir.sqrMagnitude <= backDistance * backDistance)
        {
            sheath.PutBackKnife(this);
            state = KnifeState.InSheath;

            hoverTimer         = 0;
            returning          = false;
            changedDirection   = false;
            hovered            = false;
            StuckedOnClimbable = false;
            traveledDistance   = 0;
            return;
        }

        transform.right = dir;

        Debug.DrawRay(transform.position, transform.right * speed * Time.deltaTime, Color.red);

        RaycastHit2D hit = Physics2D.Raycast(transform.position, transform.right, speed * Time.deltaTime);

        if (hit.collider != null)
        {
            var attackable = hit.collider.GetComponent <IAttackable>();

            if (attackable != null)
            {
                print("Enemy return");
                var attack = Process(basicAttack);
                attack._fromDirection = hit.collider.transform.position - transform.position;
                RaiseOnHitEvent(attackable, attackable.ReceiveAttack(ref attack), attack);
            }
        }

        transform.position += transform.right * speed * Time.deltaTime;
    }