コード例 #1
0
    void DoAction()
    {
        if (LevelManager.current_level.won == true || LevelManager.current_level.lost == true)
        {
            return;
        }

        ENEMY_ACTIONS action_to_execute = ENEMY_ACTIONS.PAUSE;

        if (!coming_back)
        {
            current_action++;
            action_to_execute = my_actions[current_action];

            if (current_action == my_actions.Length - 1)
            {
                current_action = -1;
            }
        }
        else
        {
            switch (my_actions[current_action])
            {
            case ENEMY_ACTIONS.LOOK_BACKWARDS:
                action_to_execute = ENEMY_ACTIONS.LOOK_BACKWARDS;
                break;

            case ENEMY_ACTIONS.ROTATE_LEFT:
                action_to_execute = ENEMY_ACTIONS.ROTATE_RIGHT;
                break;

            case ENEMY_ACTIONS.ROTATE_RIGHT:
                action_to_execute = ENEMY_ACTIONS.ROTATE_LEFT;
                break;

            case ENEMY_ACTIONS.MOVE:
                action_to_execute = ENEMY_ACTIONS.MOVE;
                break;

            case ENEMY_ACTIONS.PAUSE:
                action_to_execute = ENEMY_ACTIONS.PAUSE;
                break;
            }

            if (current_action == 0)
            {
                coming_back = false;
            }

            current_action--;
        }

        ExecuteAction(action_to_execute);

        Invoke("DoAction", LevelManager.current_level.action_time);
    }
コード例 #2
0
    void ExecuteAction(ENEMY_ACTIONS action)
    {
        //Debug.Log("EXECUTING ACTION:" + action.ToString());
        s_ren.flipX = false;
        Vector2 old_looking = looking_at;

        switch (action)
        {
        case ENEMY_ACTIONS.MOVE:
            Move(looking_at);
            break;

        case ENEMY_ACTIONS.ROTATE_RIGHT:
            looking_at = Quaternion.Euler(0.0f, 0.0f, -90.0f) * looking_at;
            if (Mathf.RoundToInt(Mathf.Abs(looking_at.x)) > 0.1f)
            {
                anim.SetTrigger("normalidle");
            }

            if (Mathf.RoundToInt(looking_at.y) > 0.2f)
            {
                anim.SetTrigger("goup");
            }

            if (Mathf.RoundToInt(looking_at.y) < -0.2f)
            {
                anim.SetTrigger("godown");
            }
            break;

        case ENEMY_ACTIONS.ROTATE_LEFT:
            looking_at = Quaternion.Euler(0.0f, 0.0f, 90.0f) * looking_at;
            if (Mathf.RoundToInt(Mathf.Abs(looking_at.x)) > 0.1f)
            {
                anim.SetTrigger("normalidle");
            }

            if (Mathf.RoundToInt(looking_at.y) > 0.2f)
            {
                anim.SetTrigger("goup");
            }

            if (Mathf.RoundToInt(looking_at.y) < -0.2f)
            {
                anim.SetTrigger("godown");
            }

            break;

        case ENEMY_ACTIONS.LOOK_BACKWARDS:
            looking_at = Quaternion.Euler(0.0f, 0.0f, 180.0f) * looking_at;
            if (Mathf.RoundToInt(looking_at.y) > 0.2f)
            {
                anim.SetTrigger("goup");
            }

            if (Mathf.RoundToInt(looking_at.y) < -0.2f)
            {
                anim.SetTrigger("godown");
            }
            break;

        case ENEMY_ACTIONS.PAUSE:

            break;
        }

        if (looking_at.x > 0)
        {
            s_ren.flipX = true;
        }
        else
        {
            s_ren.flipX = false;
        }

        Detect();
        //transform.rotation = Quaternion.LookRotation(Vector3.forward, new Vector3(looking_at.x, looking_at.y, 0.0f));
    }