Question by
SirDogey · Mar 06, 2017 at 10:52 PM ·
scripting problemhealth
Do Death Function Only Once.
So im trying to make a death mechanic for my game In unity. And when i die it loops the function. and i dont know how to stop it from looping. i only want it to do the part once. Code Below.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Health : MonoBehaviour {
public Transform CorpseSpawnPoint;
public GameObject Prefab;
public int health = 100;
public int maxhealth = 100;
private bool DeathSEQDone;
// Use this for initialization
void Start () {
health = 100;
maxhealth = 100;
DeathSEQDone = false;
}
// Update is called once per frame
void Update () {
if (health <= 0)
{
Debug.Log("Ded");
Instantiate(Prefab, CorpseSpawnPoint.position, CorpseSpawnPoint.rotation);
DeathSEQDone = true;
}
}
}
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220612112612im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Huge Health and Damage Script Problem 0 Answers
Interesting Script Problem 1 Answer
An object reference is required to access non-static member 2 Answers
Stopping the player from regenerating health when it takes damage 0 Answers
Health pickup script issue -1 Answers