Unity中的问题,缺少带有Instantiate(Resources.load)方法的纹理

时间:2019-06-13 18:14:37

标签: c# unity3d

我有一个问题,要实例化一个多维数据集并设置其纹理。一切都很好,但是当我尝试移动多维数据集时,它失去了纹理。我的代码在哪里出错?

起初,我尝试仅使用Resources.Load加载纹理,但是现在在查看论坛后,将其更改为Instantiate(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);
    }
}

问题在于,当多维数据集移动时,它失去了纹理。它变成一个灰色立方体。

1 个答案:

答案 0 :(得分:0)

好的,我修复了它。问题出在这一行:

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

最后一位数字0应该为1,如下所示:

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