- Home /
Question by
convictcartel · Jan 17, 2014 at 11:05 AM ·
instantiatespawnitemdrop
Item Drop Help
I made a script that should be spawning Item1 when the enemy has 0 HP, maybe im missing something because nothing happens when they die...
using UnityEngine;
using System.Collections;
public class ItemDrop : MonoBehaviour {
public Rigidbody Item1;
public Rigidbody Item2;
public Rigidbody Item3;
public Transform monster;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
AttackandHP ZS = (AttackandHP)monster.GetComponent ("AttackandHP");
if (ZS.curHealth == 0) {
Item1Spawn();
}
}
public void Item1Spawn() {
Rigidbody clone;
clone = Instantiate(Item1, monster.transform.position, monster.transform.rotation) as Rigidbody;
}
}
Comment
Chances are your curHealth is a float that has a very small chance of actually being equal to zero. Try :
if (ZS.curHealth <= 0) {
Best Answer
Answer by Benoit Dufresne · Jan 17, 2014 at 03:41 PM
Change
if (ZS.curHealth == 0) {
to
if (ZS.curHealth <= 0) {
See if that helps. Chances are your monster has taken damage higher than his remaining HP and gotten into negative.
Your answer
Follow this Question
Related Questions
Spawn enemies so they aren't spawned on top of each other (C#) 1 Answer
Respawning Single Enemy at a Random Range 1 Answer
Instantiate a Prefab with click in a certain area 2 Answers
UNet - How do I make Network.Spawn not show the prefab to the user that called it? 1 Answer
Network.Instantiate Problem 1 Answer