Unity 中缺少纹理的问题与实例化(资源.加载)方法



我有一个问题,其中实例化一个立方体并设置它的纹理。一切都很好,但是当我尝试移动立方体时,它失去了质地。我的代码哪里有问题?

起初我尝试仅使用Resources.Load加载纹理,但现在在查看论坛后将其更改为Instanceiate(Resources.Load(。但它仍然对我没有帮助。

void Start()
{
    texture = Resources.Load<Texture>("images/" + "(" + lastPic.ToString() + ")");
    textureClone = Instantiate(texture);
    pic = Instantiate(pic4, new Vector3(0, 1, 16), Quaternion.identity);
    pic.GetComponent<MeshRenderer>().material.mainTexture = textureClone;
}
// Update is called once per frame
void Update()
{
    if (GameObject.FindGameObjectsWithTag("GreyCube").Length == 0 && !flag)
    {
        pic.transform.position += velocity * Time.deltaTime;
        pic.transform.localScale = new Vector3( 18.8f, 11, 0);
    }
}

问题是当立方体移动时,它会失去纹理。它变成了一个灰色的立方体。

好的,我修复了它。问题出在这条线上:

pic.transform.localScale = new Vector3( 18.8f, 11, 0(;

最后一个数字 0 应该是 1,如下所示:

pic.transform.localScale = new Vector3( 18.8f, 11, 1(;

最新更新