Thursday, October 13, 2022
HomeGame Developmentunity - Character nonetheless performs fallen-on-ground animation after respawning

unity – Character nonetheless performs fallen-on-ground animation after respawning


My character dying animation works and when the character lies on the bottom, textual content seems saying “Wasted”. I added an object and it respawns.

The principle drawback is that though he respawns, the character nonetheless performs the animation of transferring on the bottom.

utilizing UnityEngine;
utilizing DG.Tweening;
utilizing UnityEngine.UI;
utilizing UnityEngine.SceneManagement;

public class Well being : MonoBehaviour {

 public float curHealth;
 public float maxHealth;
 public bool enemyDied = false;
 non-public Animator anim;
 public Slider healthBar;
 non-public ThirdPersonCharacter thirdPerson;
 non-public void Begin()
 {
     curHealth = maxHealth;
     healthBar.minValue = 0;
     healthBar.worth = curHealth;
     healthBar.maxValue = maxHealth;
     anim = GetComponent<Animator>();
     thirdPerson = GetComponent<ThirdPersonCharacter>();
 }
 void Replace()
 {
     float hit = anim.GetFloat("hit");
     if (hit > 0)
     {
         hit -= Time.deltaTime * 3;
         anim.SetFloat("hit", hit);
     }
     if (curHealth < 1)
     {
         Physics.SyncTransforms();
         anim.SetBool("dying", true);
     }
     if (Enter.GetKeyUp(KeyCode.House))
     {
         SendDamage(Random.Vary(10, 20));
     }
 }
 public void SendDamage(float damageValue)
 {
     curHealth -= damageValue;
     healthBar.worth = curHealth;
     if (curHealth <= 0)
     {
         enemyDied = true;
     }
     Invoke(nameof(Resurrect), 2f);
     anim.SetFloat("hit", 1);
 }
 public void Resurrect()
 {
     SpriteRenderer blackout = Digicam.primary.rework.GetComponentInChildren<SpriteRenderer>();
     Coloration orjinalRenkWasted = blackout.shade;
     Coloration clrWhitealpha0 = new Coloration(1, 1, 1, 1);
     Coloration clr = new Coloration(0, 0, 0, 1);
     blackout.rework.GetChild(0).GetComponent<SpriteRenderer>().DOColor(clr, .5f).SetDelay(2f).OnStart(() =>
     {
         blackout.DOColor(clrWhitealpha0, .5f).SetDelay(.5f).OnComplete(() =>
         {
             Invoke(nameof(BringEverythingBack), 2f);
             blackout.rework.GetChild(0).GetComponent<SpriteRenderer>().DOColor(new Coloration(0, 0, 0, 0), .5f).SetDelay(2.5f).OnStart(() =>
             {
                 blackout.DOColor(orjinalRenkWasted, .25f);
             });
         });
     });
 }

 void BringEverythingBack()
 {
     rework.root.place = GameObject.FindGameObjectWithTag("Respawn").rework.place;
 }

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments