【问题标题】:Problem in Unity with missing texture with Instantiate( Resources.load ) methodUnity 中使用 Instantiate( Resources.load ) 方法丢失纹理的问题
【发布时间】: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 .. 你想做什么?

标签: c# unity3d


【解决方案1】:

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

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

最后一位是 0 应该是 1,像这样:

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

【讨论】:

    猜你喜欢
    • 2022-11-12
    • 1970-01-01
    • 1970-01-01
    • 2016-11-14
    • 2013-04-12
    • 1970-01-01
    • 2021-09-12
    • 1970-01-01
    • 2023-03-23
    相关资源
    最近更新 更多