I have a gameobject that 2 scripts with the same name. I would like to just be able to destroy/remove 1, not both scripts. Is there a line of code that I can use that will remove the script that the code is in?
I have tried the code below but that will remove both scripts.
Destroy(this);
If I do the code below then the first script on the inspector going downwards will be removed.
Do the two scripts share the same name, but are different otherwise? If yes, then that’s bad and you should change one of the script names.
If not: You can use GetComponents to get an array of all the components of the type you specified. You can then access these components by their position in the array.
ScriptName[] scriptName_array = GetComponents<ScriptName>();
Destroy(scriptName_array1[scriptName_array1.Length - 1];//Destroys the last element in tbhe array
Destroy(scriptName_array1[1];//Destroys the second element in the array (0 is the first one).