using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class CheckIfVisible : MonoBehaviour
{
    public GameObject obj;
    public Camera cam;
    void Update()
    {
        // Detects anything rendered by gpu
        // this means that it's true for the scene view and game view

        //if (obj.GetComponent<Renderer>().isVisible)
        //{
        //    print(obj.name + " is visible!");
        //}

        // check the object's position in screen space
        Vector3 viewPos = cam.WorldToViewportPoint(obj.transform.position);
        if (viewPos.x >= 0 && viewPos.x <= 1f && viewPos.y >= 0f && viewPos.y <= 1f)
        {
            print(obj.name + " is visible!");
        }
    }
}
