Skip to content

Instantly share code, notes, and snippets.

@todorok1
Created January 3, 2021 04:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save todorok1/698198058b7e7818c8884f3d407ade6f to your computer and use it in GitHub Desktop.
Save todorok1/698198058b7e7818c8884f3d407ade6f to your computer and use it in GitHub Desktop.
ランダムなマテリアルをアタッチして地形オブジェクトを生成するサンプルです
// 生成するオブジェクトのマテリアルリストです。
public List<Material> matList;
// (中略)
/// <Summary>
/// オブジェクトをインスタンス化するメソッドです。
/// </Summary>
void InstantiateFieldParts(Vector3 pos)
{
// オブジェクトをインスタンス化します。
GameObject obj = Instantiate(fieldParts, Vector3.zero, Quaternion.identity);
// オブジェクトのTransformを設定します。
obj.transform.SetParent(fieldParent);
obj.transform.localPosition = pos;
// マテリアルをランダムにセットします。
int matIndex = Random.Range(0, matList.Count);
obj.GetComponent<MeshRenderer>().material = matList[matIndex];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment