P
P
PolakMan2020-05-11 15:55:07
C++ / C#
PolakMan, 2020-05-11 15:55:07

How to move an object to a specific point after a condition is met?

Hello, I ran into a problem, the character, after being hit 5 times, must move to the original point and the life counter returns to its previous state, the problem is that when the condition is met, the character does not move to the specified point, but the counter is updated. Tell me what can be done?

public class PlayerCharacter : MonoBehaviour
<code lang="cs">
public class PlayerCharacter : MonoBehaviour
{
    private int _health;
    // Start is called before the first frame update
    void Start()
    {
        _health = 5;
    }
    public void Hurt(int damage)
    {
        _health -= damage;
        Debug.Log("Health:" + _health);
        
    }
    // Update is called once per frame
    void Update()
    {
        if(_health == 0)
        {
            _health = 5;
            this.transform.position = new Vector3(5, 0.5f, -4);
        }
    }
}
</code>

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question