I have a prefab with attached script that I am using as a projectile. The prefab contains a model, a rigidbody, a Trail renderer and a script that moves the projectile, and when close enough to the intended target, is suppose to disappear, and destroy the prefab
snippet from calling routine (shooter)
GO=(GameObject)Instantiate(Resources.Load("cannonballprefab"),
SHIPPREFAB.rigidbody.position,new Quaternion());
GO.SendMessage("RECV_TARGET",TARGETSHIP.POS.postion);
from the script attached to the cannonballprefab:
public void RECV_TARGET(Vector3 V)
{
TARGET=V;
DIR=V-rigidbody.position;
}
public void Update()
{
Vector3 V=DIR*.1f*Time.deltaTime;
rigidbody.transform.Translate(V);
V=rigidbody.position-TARGET;
float DISTANCE=V.magnitude;
if(DISTANCE<5)
{
Destroy(this);
}
}
When the projectile meets the condition (DISTANCE<5), the script is detached from the prefab, but the object perisists inthe hierarchy.
shouldn’t destroy remove the entire prefab, or am I missing something here?