I know its been asked here a lot but any od the answers didnt helped me iam trying to create a ingame level editor ive been do happy that i found a way to spawn obejct on palyers mouse rounded position but now iam having trouble with testing if on where palyer click isnt already a block nor raycast helped me ,Spherecollider finder or whats its name i even tried to loop trought all gameobjects with tag palcable in scene but didnt worked.The game is in 2D
This is my code:
public class LevelEditor : MonoBehaviour {
public GameObject GObjectToSpawn;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
if (Input.GetMouseButtonDown(0))
{
Vector3 pz = Camera.main.ScreenToWorldPoint(Input.mousePosition);
Vector3 spawnpos3 = new Vector3(Mathf.Round(pz.x), Mathf.Round(pz.y), Mathf.Round(pz.z));
Vector2 spawnpos = spawnpos3;
Instantiate(GObjectToSpawn, spawnpos, Quaternion.identity);
}
}
}