본문 바로가기
개발/C#

유니티 C# 플랫폼 분기별 코드 작성하기 Platform 간단 사용법

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

public class Example : MonoBehaviour
{
    void Start()
    {
#if UNITY_EDITOR
        Debug.Log("유니티 에디터에서 실행");
#elif UNITY_ANDROID
        Debug.Log("안드로이드에서 실행");
#elif UNITY_IOS
        Debug.Log("아이폰에서 실행");
#elif UNITY_WEBGL
        Debug.Log("웹에서 실행");
#endif
    }
}

 

  • 다른 방법
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Example : MonoBehaviour
{
    void Start()
    {
        if(Application.platform == RuntimePlatform.Android)
        {
            Debug.Log("안드로이드에서 실행");
        }
        else if(Application.platform == RuntimePlatform.IPhonePlayer)
        {
            Debug.Log("아이폰에서 실행");
        }
        else if (Application.platform == RuntimePlatform.WebGLPlayer)
        {
            Debug.Log("웹에서 실행");
        }
        else
        {
            Debug.Log("유니티 에디터에서 실행");
        }
    }
}
반응형

댓글