A
A
artemkaw2017-10-31 19:33:48
2D
artemkaw, 2017-10-31 19:33:48

Unity C # - How, after taking damage by a character, give him invulnerability?

Hello. I am a beginner learning Unity 3D writing in C#. I'm experimenting with one game. Now I'm faced with a problem: how, when taking damage, does the main character get invulnerability, for example, for 2 seconds (he has already implemented the taking of damage)? Thanks in advance

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
MrDywar Pichugin, 2017-10-31
@artemkaw

Read the Unity3D documentation https://docs.unity3d.com/en/current/Manual/index.html Read the
introductory C# course at https://metanit.com/sharp/ The main character is the game object that the script is on, this script has the Damage(int amount) method. It checks whether the main character can take damage or not, namely the flag of immortality true/false. The flag can change under the action of the timer, the documentation has an example of its use. If immortality can still be used by someone else, then it is better to put this matter into a separate class (decorator).

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question