【发布时间】:2019-06-18 03:21:23
【问题描述】:
我有一个问题是实例化一个立方体并设置它的纹理。一切都很好,但是当我尝试移动立方体时,它失去了它的纹理。我的代码哪里错了?
起初我尝试仅使用 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);
}
}
问题是当立方体移动时它会失去它的纹理。它变成了一个灰色的立方体。
【问题讨论】:
-
创建一个prefab,它应该可以解决所有问题
-
你不能在
Texture上使用Instantiate.. 你想做什么?