Hi, having an issue with figuring out how to destroy a specific clone, creating the clones fine however cant figure out how to destroy a object I specifically want to destroy
function creating objects
//variables for catapult
public Transform[] CatapultPlace; //array to store catapult places
public GameObject CatapultPrefab; // catapult prefab
GameObject CatapultClone; //instantiated catapult
// function to place catapult
public void placecatapult()
{
CatapultClone = Instantiate(CatapultPrefab, CatapultPlace[0].transform.position,Quaternion.identity) as GameObject ;
}
function for destroying
public void removecatapult()
{
Destroy(CatapultClone[0], 0);
}
public void removecatapult()
{
Destroy(CatapultClone);
}
You dont need the [0] as it isn’t an array. You also don’t need a 0 as 0 is default.
Also next time for a headsup, you should have got compiler errors and prewarnings. You should have posted those to make it similar for people
Your code isn’t doing what you think it is then. You need to change a couple of things. Your CatapultClone is being set here
// function to place catapult
public void placecatapult()
{
CatapultClone = Instantiate(CatapultPrefab, CatapultPlace[0].transform.position,Quaternion.identity) as GameObject ;
}
It is initialized as ‘GameObject CatapultClone’ a single gameobject, a single catapult, if you want that variable to be an array you need to either declare it as a List or array. Then you can change your code accordingly. What is your desired gameplay for placecapapult and removecatapult? I’m pretty sure you have it set up wrong where this will be inefficient or require more work.