using UnityEngine;
using System.Collections;

public class Variables : MonoBehaviour {

    public string SIGNUP =  "등록";
    public string LOGIN = "로그인";
    public string LOGIN_FACEBOOK = "Facebook Login~~";

    // Use this for initialization
    void Start () {
 
    }
    
    // Update is called once per frame
    void Update () {
    
    }
}


여기 이런 스크립트가 있다. 

다른 스크립트에서 이 스크립트에 선언된 변수를 선언하는 방법은 무엇일까.

가장 먼저, 위 스크립트를 (빈) 게임오브젝트에 집어넣어 컴포넌트화 시켜놓고, GetComponent를 사용하는 방법이다.


Variables vari = GameObject.Find("Variables 컴포넌트가 부착된 오브젝트").GetComponent<Variables>();


또는 나눠서,


GameObject gameObject = GameObject.Find("Variables 컴포넌트가 부착된 오브젝트");

Variables vari = gameObject.GetComponent<Variables>();


으로 작성한다.


//////////////////


하지만, 왜 반드시 GameObject를 선언해줘야하는것인가?

그냥 변수를 가져와서 쓸 수 있는 방법은 없는걸까?

검색결과, 싱글톤 방식으로 변경을 하면 가능하다는 것을 알게 되었다.



Posted by sungho88
,