Hey all! so I have this problem and I have searched all over the web for this so I don’t even know if its possible. So basicly I’m trying to Destroy a gameobject from a different gameobject via script. Ill show you the fraction of my code it I’m talking about
public GameObject CrystalForPlaceG;
void Update()
{
if (canDestroy == 1)
{
if (Input.GetButtonDown("Destroy"))
{
Inventory.text = "Crystal";
//BuildingCrystal.SetActive(false);
//CrystalForPlaceG.SetActive(false);
//Object.Destroy(CrystalForPlaceG);
CanPlace = 1;
canDestroy = 0;
}
}
Ignore the fact that it looks like there are parts missing this is like a tiny fraction of my code and I have a ton more variables. Anyways what I’m trying to get to happen is that when you Destroy a block it Destroys the gameobject. but the problem here is I’m doing it from another script so when I play it says deleting unity assets is not permitted due to data loss. as you can see I tried multiple methods and none worked. for the set active it wouldent set the gameobject to false and then when I place another crystal it sets it false even though when I am pressing the place key (this is also in update) it sets it active but for some reason its overriding it I guess. If anyone could help that would be great. Thanks!