Im making a small tower defense game as a gift for chrismas. I dont want the tower to spawn from its spawner if its colliding with anything an enemy, a tower or a path. I’ve tried a lot of methods but none seem to work. I’ll put my code below
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class DragDrop : MonoBehaviour
{
private bool isDragging;
public GameObject Tower;
public void OnMouseDown()
{
isDragging = true;
}
public void OnMouseUp()
{
float x = transform.position.x;
float y = transform.position.y;
isDragging = false;
transform.position = new Vector3(5, 3, -1);
Vector3 spawnPos = new Vector3(x, y, -1);
Instantiate(myPrefab, spawnPos, Quaternion.identity);
}
void Update()
{
if (isDragging)
{
Vector2 mousePosition = Camera.main.ScreenToWorldPoint(Input.mousePosition) - transform.position;
transform.Translate(mousePosition);
}
}
}