new to unity. trying to make a building mode and a destruction mode. the build mode instantiates prefabs (just a cube), i want the destroy mode to destroy these cubes.
here is the code i wrote
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class destroy : MonoBehaviour
{
public Transform destroyposition;
public float destroyradius;
public Collider[] destructioncolliders;
public LayerMask destructible;
public bool destroymode;
// Start is called before the first frame update
void Start()
{
destructioncolliders = Physics.OverlapSphere(destroyposition.position, destroyradius);
}
// Update is called once per frame
void Update()
{
if (Input.GetKeyDown(KeyCode.X))
{
destroymode = !destroymode;
}
if(destroymode && Input.GetMouseButton(0))
{
//code here would destroy all destroyable cubes (set to a specific layer) in a destroyradius around
//destroyposition. i tried to make it work with a overlapsphere but couldn't figure it out.
}
}
}