I was wondering if you could make a script in java or c sharp that takes a object and divides it as if it were glass,if it is hit by raycast.Thank you for reading this and have a great day.
This can be done, since Unity allows access to the mesh, but the results may be deceptive: the mesh division algorithm may take too much time, and also produce too repetitive segments. An intermediate solution could be to create the object with a suitable triangle division, and simply “break” these triangles and convert them to meshes when the object is hit.
But if you want the pieces to fall and bounce like real world objects, forget about this method: you must create a mesh collider for each piece, a slow operation that may cause a hiccup in your game. It’s better to previously create the broken version as a prefab and replace the healthy object with it when necessary.
I recommend you to create two objects. One with one mesh, to use before it gets hit and another composed by several meshes, to replace the first one when it get’s hit.