S
S
SDHOPS2018-06-22 13:42:11
C++ / C#
SDHOPS, 2018-06-22 13:42:11

How to implement the destruction of a 2D object?

Greetings.
Perhaps one of the only answers that I could not dig up in a search engine. Destructibility of 2D objects. For example, cutting a tree like in Terraria, or if you imagine a Box, and after hitting it, destruction into small pieces that disappear afterwards. Can anyone explain the principle of implementing this system on the Unity engine? I understand everything with a crutch, and I work more not through the code, but through the engine itself) For example, in my understanding it is:
There is a character with a trigger for Hit, when the trigger is activated and the hand touches with a collision (for example) Barrels, then the Barrel object is destroyed by Destroy (col.gameObject); after which a certain system of particles is activated, producing the ejection of pieces once. I'm sorry , I just don't have much experience, so I'm writing here to find out the answer)
An example from the Sword of Xolan game:
5b2cd5197e7e9432158022.png5b2cd5229b340586125799.png

Answer the question

In order to leave comments, you need to log in

2 answer(s)
Z
Zelimkhan Beltoev, 2018-06-22
@SDHOPS

For destruction, separate objects (prefabs) are created with destruction animation. After, for example, a barrel is destroyed, the object of the barrel is removed/hidden, and in its place an object is created with the animation of the destruction of the barrel.
And the animations themselves are already being done depending on the situation: you can simply draw several changing frames with the state of the object, or you can do it with particles.

S
Suren, 2018-06-22
Jagaryan @saylar

In fact, you don’t need a new Object, as Zelimkhan writes, you just need to throw a destruction animation on the object, uncheck Looping in the animation and delete the object after the animation is completed, you can do it with Corutina or using Invoke.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question