Not having provided the code you’re actually using i can’t offer any suggestions at all as to what might be wrong in it other than to say did you actually assign normals or call recalculatenormals
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class meshTriangles : MonoBehaviour {
public Vector3[ ] newVertices;
public Vector2[ ] newUV;
public int[ ] newTriangles;
// public Vector3[ ] newNorms;
// Use this for initialization
void Start () {
Mesh mesh = new Mesh();
GetComponent().mesh = mesh;
This won’t compile. You can’t multiply an array by a float, i’m assuming you meant to multiply the i position of the array instead but then what is it supposed to be doing? you’re just trying to add new vertices to the array without ever actually using them in any triangles. And i’m not sure what creating a vertice that is the multiply of a normal direction by the sin of the gametime is getting you.
What exactly are you trying to do here, just draw a triangle that changes over time?
In what way are your normals not working for you? If it’s that your mesh is purple you haven’t assigned a material to the mesh renderer. If it’s that the triangle is facing the wrong way you need to reverse the winding order (the order in which the 3 vertices are listed)
I’m not really sure what you’re trying to achieve, but if your just trying to draw a mesh and have it increase in size over time, this works:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class meshTriangles : MonoBehaviour
{
[SerializeField]
MeshFilter MeshFilter;
public Vector3[] newVertices;
public Vector2[] newUV;
public int[] newTriangles;
Mesh mesh;
// public Vector3[] newNorms;
// Use this for initialization
void Start()
{
mesh = new Mesh();
MeshFilter.mesh = mesh;
mesh.vertices = newVertices;
mesh.triangles = newTriangles;
mesh.RecalculateNormals();
}
// Update is called once per frame
void Update()
{
newVertices[0] += (newVertices[0] * Time.deltaTime);
newVertices[1] += (newVertices[1] * Time.deltaTime);
newVertices[2] += (newVertices[2] * Time.deltaTime);
mesh.vertices = newVertices;
mesh.RecalculateBounds();
}
}
Yeah…got it…The code I posted is from the unity documentation…that’s why the thread is called ‘Mistake’. I think the code is wrong, just for future users that want to use it for any purpose ;).
You didn’t copy the code correctly, you didn’t index the vertices and normals as it shows on the Unity Mesh page. The code is correct as found on the link, yours is not
vertices += normals * Mathf.Sin(Time.time);
Correct
vertices[i] += normals[i] * Mathf.Sin(Time.time);
Also if you are going to use that code move the Mathf.Sin outside the loop.