关于Unity Texture2D在Image上的显示问题
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class ImageTest : MonoBehaviour {
public Image image;
void Start () {
}
void Update () {
}
/// <summary>
/// 点击按钮
/// </summary>
public void Onclick()
{
Texture2D texture = new Texture2D(128, 128);
image.GetComponent<Image>().material.mainTexture = texture;
for (int y = 0; y < texture.height; y++)
{
for (int x = 0; x < texture.width; x++)
{
Color color = ((x & y) != 0 ? Color.white : Color.gray);
texture.SetPixel(x, y, color);
}
}
texture.Apply();
}
}
点击按钮后不显示
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class ImageTest : MonoBehaviour {
public Image image;
void Start()
{
Texture2D texture = new Texture2D(128, 128);
image.GetComponent<Image>().material.mainTexture = texture;
for (int y = 0; y < texture.height; y++)
{
for (int x = 0; x < texture.width; x++)
{
Color color = ((x & y) != 0 ? Color.white : Color.gray);
texture.SetPixel(x, y, color);
}
}
texture.Apply();
}
}
在start中调用则显示