コガネブログ

平日更新を目標にUnityやC#、Visual Studioなどのゲーム開発アレコレを書いていきます

【Unity】【Tips】汎用関数を定義してInstantiateを短く記述する

Before

var goalEffect = GameObject.Instantiate( goalEffectPrefab ) as GameObject;

After

public static class UnityObjectUtils
{
    public static GameObject Instantiate( UnityEngine.Object original )
    {
        return UnityEngine.Object.Instantiate( original ) as GameObject;
    }
}
var goalEffect = UnityObjectUtils.Instantiate( goalEffectPrefab );