Answer the question
In order to leave comments, you need to log in
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
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 questionAsk a Question
731 491 924 answers to any question