- Home /
Mesh's Color in RawImage
I want to render a color mesh by RawImage like this:
and finished a script:
 using UnityEngine;
 using System.Collections;
 using UnityEngine.UI;
 using System.Collections.Generic;
 using CDV;
 
 public class Test : MonoBehaviour {
 
     private class Block : RawImage
     {
         Mesh m_mesh;
         protected override void UpdateGeometry()
         {
             if(m_mesh==null)
             {
                 List<Vector3> vertices = new List<Vector3>();
                 List<Color> colors = new List<Color>();
                 List<int> triangles = new List<int>();
 
                 vertices.Add(new Vector3(0f,0f, 0f));
                 vertices.Add(new Vector3(100f,0f,0f));
                 vertices.Add(new Vector3(0f, 100f, 0f));
                 vertices.Add(new Vector3(100f, 100f, 0f));
                 triangles.Add(0);
                 triangles.Add(3);
                 triangles.Add(2);
                 triangles.Add(0);
                 triangles.Add(1);
                 triangles.Add(3);
                 colors.Add(Color.blue);
                 colors.Add(Color.blue);
                 colors.Add(Color.red);
                 colors.Add(Color.red);
 
                 m_mesh = new Mesh();
                 m_mesh.RecalculateNormals();
                 m_mesh.vertices = vertices.ToArray();
                 m_mesh.triangles = triangles.ToArray();
                 m_mesh.colors = colors.ToArray();
             }
             canvasRenderer.SetMesh(m_mesh);
         }
     }
     public Canvas canvas;
     // Use this for initialization
     void Start () {
         GameObject go = new GameObject();
         go.AddComponent<Block>();
         go.GetComponent<RectTransform>().SetParent(canvas.GetComponent<RectTransform>());
         Tools.ResetTransform(go.GetComponent<RectTransform>());
     }
     
     // Update is called once per frame
     void Update () {
     
     }
 }
Actually, the rendering result seems strange, like this:
Any mistakes in my script? Thank you!!
 
                 
                qq截图20160428213322.png 
                (9.4 kB) 
               
 
                
                 
                1.png 
                (99.1 kB) 
               
 
              
               Comment
              
 
               
              Answer by egi422 · May 02, 2016 at 02:09 PM
OK, I have solved this problem myself...Color32 should be used here, but not Color...What a strange problem.
Your answer
 
 
             Follow this Question
Related Questions
Making a dynamic radar type graph 3 Answers
Unity 5.3 UI Glitch in runtime 1 Answer
Performance issue with ScrollRect.LateUpdate() 1 Answer
Rendering issue in Unity particle system on UI 0 Answers
how to test Buttons 1 Answer
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                