Unity/Csharp/mesh
提供: 初心者エンジニアの簡易メモ
- 新規でGameObjectを作成しCanvasに追加(ここではRObject)
- ヒエラルキーに新規でMaterial(ここではBlueMaterial)を作りUnlit/Colorを選択し色を選択。
- RObjectにPlaySceneRObject.csをつぶける
- Robjectを選択し、プロパティにあるblueMaterialにBlueMaterialをドラッグ
PlayScene.cs
GameObject rObject = GameObject.Find("RObject"); var mesh = new Mesh(); mesh.vertices = new Vector3[] { new Vector3 (0, 1f), new Vector3 (1f, -1f), new Vector3 (-1f, -1f), }; mesh.triangles = new int[] { 0, 1, 2 }; mesh.RecalculateNormals(); MeshFilter filter = rObject.GetComponent<MeshFilter>(); filter.sharedMesh = mesh; MeshRenderer renderer = rObject.GetComponent<MeshRenderer>(); renderer.material = rObject.GetComponent<PlaySceneRObject>().redMaterial; filter.sharedMesh = mesh;
PlaySceneRObject.cs
public class PlaySceneRObject : MonoBehaviour { public Material blackMaterial; public Material blueMaterial; public Material greenMaterial; public Material orangeMaterial; public Material pinkMaterial; public Material purpleMaterial; public Material redMaterial; public Material whiteMaterial; public Material yellowMaterial; }