OK so i just watched quill18’s destruction tutorial. he came up with this script. which pretty much says when A collides with B. B gets destroyed and replaced with C. This works perfectly if the object(C) you are instantiating is not meant to move, but in my case I need the object(C) to be parented to an other object(D), which is moving, so that object(C) moves with the moving object(D). however i am not sure how to do this. Please help?
using UnityEngine;
using System.Collections;
public class Destrutiable : MonoBehaviour {
public GameObject debrisPrefab;
public Transform DT;
void Start () {
}
void OnCollisionEnter( Collision collision)
{
if(collision.impactForceSum.magnitude > 20f)
{
DestroyMe();
}
}
void DestroyMe()
{
if(debrisPrefab)
{
Instantiate(debrisPrefab, transform.position, DT.rotation);
}
Destroy(gameObject);
}
}