I have a script that adds a LineRenderer to the parent GameObject.
When I try to destroy and readd that script to the same GameObject, it will tell me that the script can not add a LineRenderer because the old one has not been destroyed yet, even though I destroy the LineRenderer component in the OnDestroy function.
My Code:
The function that readds the component:
void OnWeaponBehaviourUpdate(string weaponBehaviourName){
Destroy(weaponInstance.GetComponent(weaponBehaviourStringOld));
weaponInstance.AddComponent(weaponBehaviourString);
}
(weaponBehaviourStringOld == weaponBehaviourString)
And this is the OnDestroy function in the readded script:
void OnDestroy(){
Destroy (lineRenderer);
}
I hope I have gave you enough code and look forward to an answer!
Thanks in advance,
Xera