-
-
Save todorok1/698198058b7e7818c8884f3d407ade6f to your computer and use it in GitHub Desktop.
ランダムなマテリアルをアタッチして地形オブジェクトを生成するサンプルです
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 生成するオブジェクトのマテリアルリストです。 | |
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