본문 바로가기
개발/C#

유니티 C# 시스템 액션 System.Action 간단 사용법

by SPNK 2022. 6. 30.
반응형
  • 코드 작성
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System;

public class Example : MonoBehaviour
{
    int a = 0;
    int b = 0;

    private void Start()
    {
        a = 5;
        b = 4;

        CheckAction(a + b, ResultAction);
    }

    public void CheckAction(int number, Action<bool> action)
    {
        if(number > 10)
        {
            action.Invoke(true);
        }
        else
        {
            action.Invoke(false);
        }
    }

    public void ResultAction(bool check)
    {
        if (check)
        {
            Debug.Log("a + b 는 10보다 큽니다.");
        }
        else
        {
            Debug.Log("a + b 는 10보다 같거나 작습니다.");
        }
    }
}
반응형

댓글