Created
June 10, 2012 01:58
-
-
Save timcash/2903529 to your computer and use it in GitHub Desktop.
Material Load
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
using UnityEngine; | |
using System.Collections; | |
public class maker : MonoBehaviour { | |
// Use this for initialization | |
void Start () { | |
Material mat = Resources.Load("unlit",typeof(Material)) as Material; | |
if(mat == null) | |
Debug.Log("mat is null"); | |
MeshRenderer mr = gameObject.AddComponent<MeshRenderer>(); | |
Mesh mesh = gameObject.AddComponent<MeshFilter>().mesh; | |
//Material mat = gameObject.AddComponent<Material>(); | |
mr.materials[0] = mat; | |
mesh.vertices = new Vector3[] {new Vector3(0, 0, 0), | |
new Vector3(0, 1, 0), | |
new Vector3(1, 1, 1)}; | |
mesh.uv = new Vector2[] {new Vector2(0, 0), | |
new Vector2(0, 1), | |
new Vector2(1, 1)}; | |
Vector3[] verts = mesh.vertices; | |
Color[] colors = new Color[verts.Length]; | |
int i = 0; | |
while (i < verts.Length) { | |
colors[i] = Color.Lerp(Color.red, Color.green, verts[i].y); | |
i++; | |
} | |
mesh.colors = colors; | |
mesh.triangles = new int[] { 0,1,2 }; | |
mesh.RecalculateBounds(); | |
} | |
// Update is called once per frame | |
void Update () { | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment