I want to destroy the prefab "Fruit" upon collision of the sprite and the parent object "Bloom", but when i test play it, it show a error saying:
Destroying assets is not permitted to avoid data loss.
If you really want to remove an asset use DestroyImmediate (theObject, true);
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class FruitRegrowth : MonoBehaviour
{
public GameObject Fruit;
public GameObject Bloom;
public bool FruitExist = true;
void Start()
{
Instantiate(Fruit, transform);
}
void OnCollisionEnter2D(Collision2D collision)
{
if (collision.gameObject.name == "Sprite")
{
Destroy(Fruit);
FruitExist = false;
Debug.Log(collision.gameObject.name);
}
}
}
Thanks for the help man i appreciate ya
– A1fredo