Hello, i have struggled with this issue for about 2 days now and cant find anything on the internet about it.
This is all the parts of the script
//This variable is located in the player script
var dagger_pref : Rigidbody2D;
//This function is located in the dagger script
function OnCollisionEnter2D(col : Collision2D)
{
if(col.gameObject.tag == "Block")
{
Destroy(gameObject);
}
if(col.gameObject.tag == "Enemy")
{
Destroy(col.gameObject);
Destroy(gameObject);
}
}
The problem is that when i call for the object to be destroyed in the game, it also destroys the prefab that is attached to the playerscript which disables the player from using the daggers at all. I have tried with Destroy(this.gameObject) and Destroy(this.rigidbody2D), but they both yielded the same results. If anyone knows how to make the prefab stay in the inspector after it has been destroyed in the game i would appreciate an answer very much.
Thanks in advance.
Where is that script located?
– huntsfromshadowThe dagger_pref variable is located in the player script so its not in the same script as the rest of the code. The rest of the code is in a script called dagger script that is attached to the dagger prefabs.
– mcsweden1The object which you want to destroy, how that comes in scene? By Instantiate?
– mrpalashYep, its instantiated from the player script
– mcsweden1The object does get destroyed, but the prefab that i have attached to a Rigidbody2D in the player script gets destroyed/deleted as well. I only want the object that actually is in the game to go away.
– mcsweden1