Unity で Resources.load()を使って Texture 2D を呼び出したい。

Unity

Sprite で呼び出す場合と異なり、Texture 2D の設定に細かい修正が必要だったので覚書。

Importしたpng を inspector view で修正

以下の画像のように修正

Texture Type : From Sprite to “Default”

Advanced -> Read/Write Enabled “Check”

Script

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using EasyMobile;
using UnityEngine.UI;

public class ImportT2dManager : MonoBehaviour
{
    Texture2D texture2d; 
	Sprite    sprite;
   
    private void Awake()
    {
        texture2d = ScreenShotManager.screenShotInfo.texture = Resources.Load("Texture2dImage", typeof(Texture2D)) as Texture2D;
        sprite = Resources.Load<Sprite>("SpriteImage");
    }
}

おしまい

コメント

タイトルとURLをコピーしました