I want to map a Square Texture to a Hex Shaped Mesh. I have the Mesh with 4 Triangle & 6 Vertices. I want to do this using Code, dynamically.
Here is the Code I used.
Script Name : “Plance.cs”
using UnityEngine;
using System.Collections;
public class Plane : MonoBehaviour
{
public Vector3[] Vertices;
public Vector2[] UV;
public int[] Triangles;
void MeshSetup ()
{
float halfHeight = 0;
Vertices = new Vector3[] {
new Vector3 (-1, halfHeight, 0),
new Vector3 (-.5f, halfHeight, Mathf.Sqrt (3) / -2),
new Vector3 (.5f, halfHeight, Mathf.Sqrt (3) / 2),
new Vector3 (-.5f, halfHeight, Mathf.Sqrt (3) / 2),
new Vector3 (.5f, halfHeight, Mathf.Sqrt (3) / -2),//
new Vector3 (1, halfHeight, 0)//
};
UV = new Vector2[] {
new Vector2 (0.5F, 0.87F),
new Vector2 (0.87F, 0.13F),
new Vector2 (0.13F, 0.87F),
new Vector2 (0.87F, 0.87F),
new Vector2 (0.13F, 0.13F),
new Vector2 (0.5F, 0.13F)
};
Triangles = new int[] {
0,3,1,
3,2,1,
1,2,4,
4,2,5
};
}
void Start ()
{
MeshSetup ();
Mesh stuff = new Mesh ();
gameObject.AddComponent<MeshFilter> ().mesh = stuff;
stuff.vertices = Vertices;
stuff.triangles = Triangles;
stuff.uv = UV;
}
}
I have attached this Script to an Empty Game Object. It has a Material attached to it with the Texture.
I have attached the Exported Package.
Click Here to Download Unity Package
I need it to look like this :
This is how it looks like now :
Immediate responses are appreciated.

