コード例 #1
0
    private void Update()
    {
        counter = Mathf.Min(counter + Time.deltaTime, cooldown);

        if (target != null)
        {
            RaycastHit2D hit = Physics2D.CircleCast(transform.position, 0.5f, target.position - transform.position, range);
            if (hit.transform == target)
            {
                isAttacking = true;
                agent.Stop();
                if (counter >= cooldown)
                {
                    Instantiate(bullet).GetComponent <MBProjectileMgr>().Initialize(transform.position, target.position, self.Faction);
                    counter = 0;
                }
            }
            else
            {
                isAttacking = false;
            }
        }
        else
        {
            isAttacking = false;
        }
    }
コード例 #2
0
    /// <summary>
    /// Sets direction for when the character and used by player when in combat
    /// </summary>
    public void SetDirection()
    {
        //player
        if (gameObject == GameManagerScript.ins.player)
        {
            if (CombatManager.ins.combatHUDLog.IsEmpty)
            {
                polyNav.Stop();
            }
            if (spellQueue.Count != 0)
            {
                if (spellQueue[0].fireMode == CombatHUDAttack.FireMode.TARGET)
                {
                    direction = FaceDirection(CombatManager.ins.combatHUDAttack.memory[spellQueue[0].attackTarget]);
                }
                else if (spellQueue[0].fireMode == CombatHUDAttack.FireMode.POINT)
                {
                    direction = FaceDirection(spellQueue[0].attackPointModePoint);
                }
                else
                {
                    direction = FaceDirection(gameObject.transform.position + spellQueue[0].attackDirection);
                }
                return;
            }
        }

        //player movement and npc movement
        if (polyNav.movingDirection == Vector2.zero)
        {
            return;
        }
        int x = 0;
        int y = 0;

        if (polyNav.movingDirection.x > 0.225f)
        {
            x = 1;
        }
        else if (polyNav.movingDirection.x < -0.225f)
        {
            x = -1;
        }
        if (polyNav.movingDirection.y > 0.225f)
        {
            y = 1;
        }
        else if (polyNav.movingDirection.y < -0.225f)
        {
            y = -1;
        }
        switch (x)
        {
        case -1:
            switch (y)
            {
            case -1:
                direction = Direction.FRONTLEFT;
                break;

            case 1:
                direction = Direction.BACKLEFT;
                break;

            default:
                direction = Direction.LEFT;
                break;
            }
            break;

        case 1:
            switch (y)
            {
            case -1:
                direction = Direction.FRONTRIGHT;
                break;

            case 1:
                direction = Direction.BACKRIGHT;
                break;

            default:
                direction = Direction.RIGHT;
                break;
            }
            break;

        case 0:
            switch (y)
            {
            case -1:
                direction = Direction.FRONT;
                break;

            case 1:
                direction = Direction.BACK;
                break;

            default:
                break;
            }
            break;
        }
    }