ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • [게임엔진활용] 12강 콤보시스템
    [DSU] 게임엔진활용 2026. 6. 8. 01:27
    728x90

    콤보시스템 구현 방법의 이해

    - 스페이스키를 누르면 콤보1 이벤트 발생

    - 콤보1 동작시 엔터키를 누르면 콤보2 이벤트 발생

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    using UnityEngine;
    using UnityEngine.InputSystem;
    using UnityEngine.InputSystem.Controls;
     
    public class GameCombo : RenderView
    {
        class Frame
        {
            public Frame(int index, float delta, Rect rtAtt)
            {
                this.index = index;
                this.delta = delta;
                this.rtAtt = rtAtt;
            }
     
            public int index;// Texture tex;
            public float delta;
            public Rect rtAtt;
        }
     
        class Combo
        {
            public Frame[] frame;
            public int frameIndex;
            public KeyControl key;
            public Combo nextCombo;
        }
     
        Combo[] combo;
     
        string[] str = {
            "주먹1-1""주먹1-2""주먹1-3",
            "주먹2-1""주먹2-2"
        };
     
        bool att;
        int comboIndex, frameIndex;
        float delta;
     
        public override void load()
        {
            combo = new Combo[2];
            Combo c = new Combo();
            c.frame = new Frame[3];
            c.frame[0= new Frame(00.1f, new Rect(0000));
            c.frame[1= new Frame(10.2f, new Rect(0000));
            c.frame[2= new Frame(20.3f, new Rect(004040));
            combo[0= c;
     
            c = new Combo();
            c.frame = new Frame[8];
            c.frame[0= new Frame(00.1f, new Rect(0000));
            c.frame[1= new Frame(10.2f, new Rect(0000));
            c.frame[2= new Frame(20.3f, new Rect(004040));
            c.frame[3= new Frame(30.1f, new Rect(0000));
            c.frame[4= new Frame(40.1f, new Rect(004040));
            c.frame[5= new Frame(00.1f, new Rect(0000));
            c.frame[6= new Frame(10.2f, new Rect(0000));
            c.frame[7= new Frame(20.3f, new Rect(004040));
            combo[1= c;
     
            combo[0].key = Keyboard.current.spaceKey;
            combo[0].nextCombo = combo[1];
     
            combo[1].key = Keyboard.current.enterKey;
            combo[1].nextCombo = null;
     
            att = false;
            comboIndex = 0;
            frameIndex = 0;
            delta = 0.0f;
        }
     
        public override void free()
        {
        }
     
        public override void draw(float dt)
        {
            setStringSize(30);
            setStringRGBA(0.5f, 0.5f, 0.5f, 1.0f);
            for (int i = 0; i < combo.Length; i++)
            {
                drawString("콤보"+(1+i)+":"1040 * i, TOP | LEFT);
                Combo c = combo[i];
                for (int j = 0; j < c.frame.Length; j++)
                {
                    Frame f = c.frame[j];
                    drawString(str[f.index], 110 + 130 * j, 40 * i, TOP | LEFT);
                }
     
            }
            if (att)
            {
                setStringRGBA(1.0f, 1.0f, 0.0f, 1.0f);
                int i = comboIndex;
                drawString("콤보" + (1 + i) + ":"1040 * i, TOP | LEFT);
                setStringRGBA(1.0f, 1.0f, 1.0f, 1.0f);
                Combo c = combo[comboIndex];
                Frame f = c.frame[frameIndex];
                drawString(str[f.index],
                    110 + 130 * frameIndex, 40 * comboIndex, TOP | LEFT);
     
                delta += dt;
                if( delta >= f.delta)
                {
                    delta -= f.delta;
                    frameIndex++;
                    if (frameIndex == c.frame.Length)
                    {
                        att = false;
                        comboIndex = 0;
                        frameIndex = 0;
                    }
                }
     
                if (comboIndex == 0)
                {
                    if (combo[1].key.wasPressedThisFrame)
                    {
                        comboIndex++;
                    }
                }
            }
            else
            {
                if (combo[0].key.wasPressedThisFrame)
                {
                    att = true;
                    comboIndex = 0;
                    frameIndex = 0;
                    delta = 0.0f;
                }
            }
     
            //if (Keyboard.current.wKey.wasPressedThisFrame)
        }
     
        public override void mouse(int stat, float x, float y)
        {
        }
    }
     
    cs

     

     

     

     

Designed by Tistory.