I have a procedurally generated plane mesh in Unity. I am sending raycasts at runtime which will collide with particular triangles in the mesh, and am getting the index of the triangle using RaycastHit's triangleIndex field.
I want a triangle to become transparent when the raycast hits it at runtime. What would be the best way to do this?
CodePudding user response:
you could get the gameobject or mesh renderer; then either disable the mesh renderer on it or disable the whole gameobject.
[SerializeField]
private MeshRenderer obj;
// in your other function you would then run after the raycast hits
obj.enabled = false;
if it had a box collider that you still wanted you wouldn't disable the whole object
CodePudding user response:
You would have to access the mesh's triangles, change that array so the triangle your trying to make transparent is actually removed from the mesh, afaik this is the only way.
var tris = mesh.triangles;
tris[yourTriangle] = null;
mesh.triangles = tris;
Sorry am not able to test this code.