예제 #1
0
    IEnumerator Normal_Attack()
    {
        player.ActionOccupied = true;
        Vector3 Target = player.GetMouseWorldpos();

        if (Target.x > transform.position.x)
        {
            transform.rotation = Quaternion.Euler(0, 0, 0); player.headingTo = Vector2.right;
        }
        else
        {
            transform.rotation = Quaternion.Euler(0, 180, 0); player.headingTo = Vector2.left;
        }

        //player.RBody.velocity = player.headingTo * 5;

        switch (AttackedNumber)
        {
        case 0:
            AttackedNumber = 1;
            player.anim.Play(AniState_NormalAttack1, -1, 0f);
            AttackHitbox.SetActive(true);
            Instantiate(AttackEffect, AttackEffectOrigin.position, transform.rotation);
            break;

        case 1:
            AttackedNumber = 2;
            player.anim.Play(AniState_NormalAttack2, -1, 0f);
            AttackHitbox.SetActive(true);
            Instantiate(AttackEffect2, AttackEffectOrigin.position, transform.rotation);
            break;

        case 2:

            AttackedNumber = 0;
            player.anim.Play(AniState_NormalAttack3, -1, 0f);
            AttackHitbox.SetActive(true);
            Instantiate(AttackEffect, AttackEffectOrigin.position, transform.rotation);
            break;
        }

        yield return(new WaitForSeconds(AttackTime));

        AttackHitbox.SetActive(false);
        player.ActionOccupied = false;
        yield return(null);
    }
예제 #2
0
    IEnumerator ThrowPickaxe()
    {
        player.anim.Play(AniState_ThrowReady);

        player.ActionOccupied = true;
        TimeManager.Instance.SetTimeScale(0.2f);

        Vector3 Target = Vector3.zero;

        while (Input.GetKey(player.throwP))
        {
            Target = player.GetMouseWorldpos();
            if ((Target - transform.position).magnitude > PickaxeThrowReach)
            {
                Target = (Target - transform.position).normalized * PickaxeThrowReach + transform.position;
            }

            if (Target.x > transform.position.x)
            {
                transform.rotation = Quaternion.Euler(0, 0, 0);
            }
            else
            {
                transform.rotation = Quaternion.Euler(0, 180, 0);
            }

            Debug.DrawLine(transform.position, Target);

            yield return(new WaitForSeconds(0.02f));
        }
        player.anim.Play(AniState_ThrowPickaxe);

        TimeManager.Instance.SetTimeScale(1.0f);

        float Speed       = 0.15f;
        float MaxReaching = 0.9f;
        float Reaching    = 0.0f;
        bool  Reached     = false;
        bool  Returned    = false;

        PickAxe.SetActive(true);
        PickaxeChain.SetActive(true);

        while (!Returned)
        {
            if (!Reached)
            {
                Speed    -= Speed / 13f;
                Reaching += Speed;
                if (Reaching >= MaxReaching)
                {
                    Reached = true;
                }

                if (PickAxe.GetComponent <BoxCollider2D>().IsTouchingLayers(player.TerrainLayer))
                {
                    Reached = true;
                }
            }
            else
            {
                Speed    += Speed / 13f;
                Reaching -= Speed;
                if (Reaching < 0.1f)
                {
                    Returned = true;
                }
            }

            PickAxe.transform.position = Vector3.Lerp(transform.position, Target, Reaching);

            PickAxe.transform.rotation  = Quaternion.Euler(0, 0, Mathf.Atan2(Target.y - transform.position.y, Target.x - transform.position.x) * Mathf.Rad2Deg);
            PickAxe.transform.rotation *= Quaternion.Euler(0, 0, -90);

            Debug.DrawLine(transform.position, Target, Color.red, 1.0f);

            yield return(new WaitForSeconds(0.02f));
        }

        player.anim.SetTrigger(AniPar_PickaxeReturned);
        PickAxe.SetActive(false);
        PickaxeChain.SetActive(false);
        player.ActionOccupied = false;
    }