Did someone put a time delay to the death animation in the TileVania Course? (course 209) the level respawn is to fast, and i cant find a good way to put some delay.
Hi Sebas,
What do you mean by respawn? The restart of the level? If so, you could call the TakeLife method via the Invoke method. See the API.
Yes. Whenever i die and the level restart, it happens too fast.
Great! I didnt know about the Invoke method. So i invoke in GameSession Script, and it would be like this?
void Start () {
livesText.text = playerLives.ToString();
scoreText.text = score.ToString();
Invoke(“TakeLife”, 2);
}
So it will delay the restart of the level 2 seconds right?
The Invoke method doesnt work, the player dies and start the level again without delay.
I was thinking making a StartCoroutine.
Does Invoke use real time for the delay? Try increasing the delay number to a large number and see if that does anything.
Thanks! but i already solved it
I created a StartCoroutine with Die();
like this:
void Update()
{
if (!isAlive)
{
return;
}
Walk();
ClimbLadder();
Jump();
FlipSprite();
StartCoroutine(Die());
}
and change Private void Die() to:
private IEnumerator Die()
{
if (myBodyCollider2D.IsTouchingLayers(LayerMask.GetMask("Enemy Blob", "Hazards")))
{
isAlive = false;
myAnimator.SetTrigger("Die");
GetComponent<Rigidbody2D>().velocity = death;
**yield return new WaitForSeconds(deathDelay);**
FindObjectOfType<GameSession>().ProcessPlayerDeath();
}
Does your coroutine work?
See also:
- Forum User Guides : How to apply code formatting within your post
Yes. It worked
This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.