How can I hide a part of a mesh at runtime?
Hi everyone. I have been reading a lot about this topic in other Unity forums, I am trying to make a clothing equipment system, if I combine two parts of clothing (t-shirt and pants, for example) from two different sets, these overlap and it is seen that the pants go through the mesh of the shirt. In these articles, I have read that you can hide the mesh by setting the alpha channel of the desired vertex color to zero. And in the attached image, it is seen working (however, he did not leave any script to guide me). I tried to reproduce it and follow the steps , but could not get it to work in any way. So my question is: Does anyone know that they can fail? (I'll leave the example script I tried to use) Also, does anyone know of some other method that "cuts the mesh" in the same precise way or more? Since I only want to hide what is necessary so that the clothes do not overlap. (Note: I have already tried using UMA2 and I do not plan to use it)
The link to the other forum: Unity Forum
The Script:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class TestCutMesh : MonoBehaviour
{
[SerializeField]
private MeshFilter bigPMesh;
[SerializeField]
private Mesh rawBigPMesh;
[SerializeField]
private Color[] vertexColors;
// Start is called before the first frame update
void Start()
{
rawBigPMesh = bigPMesh.mesh;
vertexColors = new Color[rawBigPMesh.vertexCount];
}
// Update is called once per frame
void Update()
{
rawBigPMesh.colors = vertexColors;
}
}
Your answer
