Quantcast
Channel: Questions in topic: "die"
Viewing all articles
Browse latest Browse all 115

When health is 0, character still lives

$
0
0
Hi all. I'm a total programing noob, and This script wont work. The idea is, when the health <= 0, he it should Destroy Object. However, nothing happens, and the Health counter simply goes negative, forever... Any ideas? Thanks in advance. var destroyedPrefab : GameObject; var destroyedPrefabfx : GameObject; var health : int = 3; private var damage : int = 1; function OnCollisionEnter (col : Collision) { if(col.gameObject.tag=="Enemy") { health -= damage; } } function update (){ if(health <= 0) { Destroy(gameObject); Instantiate(destroyedPrefab, transform.position, transform.rotation); Instantiate(destroyedPrefabfx, transform.position, transform.rotation); var guiText = GameObject.Find("GUI Text").GetComponent(GUIText); guiText.text = myNiceVariable; } }

Viewing all articles
Browse latest Browse all 115

Trending Articles