简体   繁体   中英

Unity C# script, continously change mesh

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.

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()
    { 

        ...

    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM