Hi
Since I couldn´t find a satisfying soltion to my problem, I´ll simply ask.
I´m trying to generate a mesh (since it´s my first only a triangle for now). The triangle is being displayed but not at the position I would expect it. I added my script to an empty and actually was expecting that the triangle apperas right at the empty´s position. Well it´s not.
Here´s the code:
using UnityEngine;
using System.Collections;
[ExecuteInEditMode]
[System.Serializable]
[RequireComponent(typeof(MeshRenderer))]
[RequireComponent(typeof(MeshFilter))]
public class AdaptiveMeshTile : MonoBehaviour {
public int scale = 1;
public Material material;
private Mesh tileMesh;
// Use this for initialization
void Start () {
this.tileMesh = new Mesh();
}
// Update is called once per frame
void Update () {
Vector3[] vertices = new Vector3[]
{
this.transform.InverseTransformPoint(new Vector3(this.transform.position.x, 0, this.transform.position.z)),
this.transform.InverseTransformPoint(new Vector3(this.transform.position.x + scale, 0, this.transform.position.z)),
this.transform.InverseTransformPoint(new Vector3(this.transform.position.x, 0, this.transform.position.z + scale))
};
Vector2[] uv = new Vector2[]
{
new Vector2(0, 256), new Vector2(256, 256), new Vector2(256, 0)
};
int[] tris = new int[]
{
2,1,0
};
Debug.Log(this.tileMesh);
this.tileMesh.vertices = vertices;
this.tileMesh.uv = uv;
this.tileMesh.triangles = tris;
this.GetComponent<MeshFilter>().mesh = this.tileMesh;
this.GetComponent<MeshRenderer>().material = this.material;
}
}
And here´s my result:
I´d rather expect something like this (Done by empty overlap to recreate the desired effect):
Disclaimer: I´m not good at math so eventual calculations should be explained in detail xD
Thanks in advance.