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

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

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

[ad_1]

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 major downside is that though he respawns, the character nonetheless performs the animation of shifting on the bottom.

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

public class Health : MonoBehaviour {

 public float curHealth;
 public float maxHealth;
 public bool enemyDied = false;
 personal Animator anim;
 public Slider healthBar;
 personal ThirdPersonCharacter thirdPerson;
 personal void Start()
 {
     curHealth = maxHealth;
     healthBar.minValue = 0;
     healthBar.worth = curHealth;
     healthBar.maxValue = maxHealth;
     anim = GetComponent<Animator>();
     thirdPerson = GetComponent<ThirdPersonCharacter>();
 }
 void Update()
 {
     float hit = anim.GetFloat("hit");
     if (hit > 0)
     {
         hit -= Time.deltaTime * 3;
         anim.SetFloat("hit", hit);
     }
     if (curHealth < 1)
     {
         Physics.SyncTransforms();
         anim.SetBool("demise", true);
     }
     if (Input.GetKeyUp(KeyCode.Space))
     {
         SendDamage(Random.Range(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 = Camera.major.rework.GetComponentInChildren<SpriteRenderer>();
     Color orjinalRenkWasted = blackout.shade;
     Color clrWhitealpha0 = new Color(1, 1, 1, 1);
     Color clr = new Color(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 Color(0, 0, 0, 0), .5f).SetDelay(2.5f).OnStart(() =>
             {
                 blackout.DOColor(orjinalRenkWasted, .25f);
             });
         });
     });
 }

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

[ad_2]

LEAVE A REPLY

Please enter your comment!
Please enter your name here