Horje
how to make a system to check if i see certain object in unity Code Example
how to make a system to check if i see certain object in unity
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
 
public class CameraFrustumTracking : MonoBehaviour
{
    public Camera displayCamera;
 
    public GameObject []Targets;
 
    // Start is called before the first frame update
    void Start()
    {
        if (displayCamera == null)
        {
            displayCamera = Camera.main;
        }
 
        Targets = GameObject.FindGameObjectsWithTag("Target");
    }
 
    // Update is called once per frame
    void Update()
    {
        foreach (GameObject target in Targets)
        {
 
            Plane[] planes = GeometryUtility.CalculateFrustumPlanes(displayCamera);
            if (GeometryUtility.TestPlanesAABB(planes, target.GetComponent<Collider>().bounds))
            {
                print("The object" + target.name + "has appeared");
                target.GetComponent<MeshRenderer>().enabled = true;
            }
            else
            {
                //print("The object" + target.name + "has disappeared");
                target.GetComponent<MeshRenderer>().enabled = false;
            }
 
        }
    }
}




Csharp

Related
c# datagridview filter Code Example c# datagridview filter Code Example
browser folder in wpf Code Example browser folder in wpf Code Example
linq string comparison case insensitive Code Example linq string comparison case insensitive Code Example
stroke dash array wpf Code Example stroke dash array wpf Code Example
c sharp system pause equivelent Code Example c sharp system pause equivelent Code Example

Type:
Code Example
Category:
Coding
Sub Category:
Code Example
Uploaded by:
Admin
Views:
8