示例#1
0
    private IEnumerator Attack()
    {
        AttackHitbox atkHitbox = Instantiate(atkHitboxPrefab, player.transform).GetComponent <AttackHitbox>();

        atkHitbox.damage = tool.damage;
        atkHitbox.range  = tool.range;

        Vector2 spawnPos = new Vector2(atkSpawnPositions[player.pMovement.direction].localPosition.x,
                                       atkSpawnPositions[player.pMovement.direction].localPosition.y);
        float posScale = (atkHitbox.range / 2) > 1 ? atkHitbox.range / 2 : 1;

        atkHitbox.transform.localPosition = new Vector2(spawnPos.x * posScale, spawnPos.y * posScale);
        atkHitbox.transform.rotation      = atkSpawnPositions[player.pMovement.direction].rotation;
        atkHitbox.player = player;

        player.pAnimations.AttackAnimation();

        yield return(new WaitForSeconds(.05f));

        Destroy(atkHitbox.gameObject);

        tool.Attacked();
    }