Unity 设置游戏对象纹理列表的 WrapMode
Unity Setting WrapMode of List Of GameObject's Textures
我想更改游戏对象列表的纹理环绕模式。
我能想到的简单算法:
--游戏对象列表
--对于每个 GameObject ,GameObject.texturewrapMode = repeat
但是我做不到,请帮助我。
希望我理解正确。如果你有一个包含 GameObject
的 List<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 关键字 generic
、foreach
、enum
。如果你知道这些,抱歉说教了 :)
我想更改游戏对象列表的纹理环绕模式。 我能想到的简单算法: --游戏对象列表 --对于每个 GameObject ,GameObject.texturewrapMode = repeat
但是我做不到,请帮助我。
希望我理解正确。如果你有一个包含 GameObject
的 List<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 关键字 generic
、foreach
、enum
。如果你知道这些,抱歉说教了 :)