Hi there guys
I have been trying to select objects through a normalized viewport, but with no luck. I have 4 cameras and the one that I want to select from is at depth 2. I instantiate objects inside this camera and give them names 0,1,2,3,4 etc, which is working perfectly. The problem is that I need to be able to select an object insode the viewport and delete it, but I just cant seem to sort the selection part out! here is what I have at the moment, it is inside a script that is attached to an empty game object:
public class selectableObject : MonoBehaviour
{
void Update()
{
if (Input.GetButton("Fire1") camera.pixelRect.Contains(Input.mousePosition))
{
RaycastHit hit = new RaycastHit();
Ray ray = camera.ScreenPointToRay(Input.mousePosition);
if (Physics.Raycast(ray, out hit))
{
print(hit.collider.gameObject.name);
}
}
}
Any help is appreciated, thanks
edit: I just updated this code. It seems to work now, but something strange: When I click on an object the first time, the print works. when I click on another object and then on that same one again, the print doesn’t change…