ref 참조 / bool 형 메소드에서 매개변수로 복제 하지 않고 받아오기

using UnityEngine;
using System.Collections;

public class test : MonoBehaviour
{
     
    bool testType = true;

    void TestMethod(bool type)
    {
        type = false;
        Debug.Log(testType); // 복제가 되어 다른 변수가 되므로 true
    }

    void TestMethodRef(ref bool type)
    {
        type = false;
        Debug.Log(testType); // ref(참조) 선언으로 원래 변수 그대로 사용 하므로 false
    }

    void Start()
    {
        TestMethod(testType);
        TestMethodRef(ref testType);
    }

}


ref 설명
https://msdn.microsoft.com/ko-kr/library/14akc2c7.aspx

댓글

이 블로그의 인기 게시물

날짜 시간 시간차 시간 계산 하기

코루틴에서 CallBack 함수 적용하기

C++ 언어 퍼센트 구하는 방법 / 기본 언어 퍼센트 구하는 방법