Hello unityAnswers its me again with another annoying question. This one may be more straightforward.
Is it possible to somehow use Camera.main.WorldToScreenPoint or ScreenToWorldPoint to check if two colliders are overlaping in screen space ?(I’m not looking for if they overlap in WorldSpace, that’s easy anyway)
Raycast is the way to solve your original problem. Here is a test test script.
using UnityEngine;
using System.Collections;
public class RandomObjects : MonoBehaviour {
public GameObject goGenerate; // Game object to generate
public Camera cam; // Camera to use for the raycast
public GameObject goCrosshairs;
Plane plane;
void Start ()
{
plane = new Plane(Vector3.forward, new Vector3(0,0,cam.gameObject.transform.position.z + 0.5f));
for (int i = 0; i < 35; i++) // Generate some random objects
{
Vector3 v3Pos = Random.insideUnitSphere * 5.0f;
v3Pos.x *= 2.0f;
Instantiate (goGenerate, v3Pos, Quaternion.identity);
}
}
void Update ()
{
Ray ray = cam.ScreenPointToRay(Input.mousePosition);
float fDist = 0.0f;
RaycastHit hit;
plane.Raycast (ray, out fDist);
goCrosshairs.transform.position = ray.GetPoint (fDist);
if (Input.GetMouseButtonDown (0))
{
if (Physics.Raycast(ray, out hit))
{
Destroy (hit.collider.gameObject);
}
}
}
}