Reputation: 59
I am trying to write a C# script for unity 3d. I want this script to continuously change my mesh that I have created. I can not figure out what I should do further. `
void UpdateMesh()
{
mesh.Clear();
mesh.vertices = vertices;
mesh.triangles = triangles;
MeshCollider collider = gameObject.AddComponent<MeshCollider>();
mesh.RecalculateNormals();
// for loop can go here
for (var i = 0; i < vertices.Length; i++)
{
vertices[i] += normals[i] * Mathf.Sin(Time.time);
}
normals = mesh.normals;
}`
This is my Update Mesh function.
Upvotes: 1
Views: 472
Reputation: 64
first of all, you should add a script component in your Unity project.
you can watch how to add the script in https://docs.unity3d.com/Manual/CreatingAndUsingScripts.html
and then on, you can use Update() function in UnityEngine class for calling your own function.
using UnityEngine;
using System.Collections;
public class YourClass : MonoBehaviour
{
void Update()
{
UpdateMesh()
}
void UpdateMesh()
{
...
}
}
Upvotes: 1