Unity设置GameObject纹理列表的WrapMode

时间:2017-02-25 18:06:39

标签: c# unity3d unity5

我想更改GameObjects列表的纹理包装模式。 我能想到的简单算法: - GameObjects列表 - 对于每个GameObject,GameObject.texturewrapMode = repeat

但我不能那样帮助我。

1 个答案:

答案 0 :(得分:0)

我希望我能正确理解这个问题。如果您有一个List<GameObject>列表,其中包含GameObject(显然),那么您可以通过以下代码设置WrapMode代码:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class txWrap : MonoBehaviour
{
    public List<GameObject> myGameObjects;

    // Use this for initialization
    void Awake ()
    {
        /*
         * IMPORTANT: if you use those textures' wrap mode ever again,
         * ESPECIALLY during runtime, use similar method to get the components to
         * another List, with the generic type of List<Texture>. 
         * GetComponent is slow and prone to error, use it runtime as few as possible. 
         */ 
        foreach(var item in myGameObjects)
        {
            item.GetComponent<Texture>().wrapMode = TextureWrapMode.Repeat;
        }
    }
}

现在,如果您不熟悉编码,您可能希望Google使用关键字genericforeachenum。如果你知道那些,抱歉是在说教:)