Hello,
I am trying to make the following script destroy all the balloon clones in the scene but it is not working.
If I use the line Destroy(Balloons) it gives me the error Destroying Assets is not permitted to avoid data loss.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.Linq;
public class WipeOut : MonoBehaviour
{
//public GameObject WipeOutCounterInternal;
NumOfWipeOutsCounter WipeOutCounterInternal;
public GameObject WipeOutPrefab;
public GameObject Balloons;
bool allowWipeOut = false;
public NumOfWipeOutsCounter numOfWipeOutsCounter;
GameObject temp;
// Start is called before the first frame update
void Start()
{
numOfWipeOutsCounter = WipeOutCounterInternal.GetComponent<NumOfWipeOutsCounter>();
temp = GameObject.Find("Balloons" + "(Clone)");
}
// Update is called once per frame
void Update()
{
if (numOfWipeOutsCounter.WipeOuts >= 0)
{
allowWipeOut = true;
}
if (allowWipeOut = true && Input.GetKeyDown("space"))
{
Instantiate(WipeOutPrefab);
numOfWipeOutsCounter.WipeOuts--;
Destroy(temp);
if(numOfWipeOutsCounter.WipeOuts == 0)
{
allowWipeOut = false;
numOfWipeOutsCounter.WipeOuts = 0;
}
}
}
}
Many thanks,
Josh Keedy.