I’m trying to destroy part of my enemy and instantiate a damaged version of that part in its place (kind of a ragdoll effect).
I can destroy the object fine but the object I want to instantiate doesn’t appear when the original object is destroyed.
using UnityEngine;
using System.Collections;
public class DestroyClaw : MonoBehaviour
{
public GameObject invaderExplosion;
public GameObject brokenClaw;
public int clawHealth = 3;
void OnTriggerEnter (Collider other)
{
if (other.tag == "Shot")
{
Debug.Log ("Hit Registered");
clawHealth -= 1;
Destroy(other.gameObject);
}
}
void Update()
{
if(clawHealth <= 0)
{
Instantiate(invaderExplosion, transform.position, transform.rotation);
GameObject item = GameObject.Instantiate(brokenClaw, transform.position, transform.rotation)as GameObject;
item.transform.parent = gameObject.transform;
MiniBossHealth.clawsAttached -= 1;
Destroy(transform.parent.gameObject);
}
}
}
I’m getting the Debug logs, the clawHealth is counting down on each hit, even the explosion instantiates but the replacement part doesn’t appear?
Any ideas as to why
???