Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

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;
            }
 
        }
    }
}
Comment

PREVIOUS NEXT
Code Example
Csharp :: c# while true loop 
Csharp :: serial begin 
Csharp :: c# mock ref parameter 
Csharp :: c# get executing file name 
Csharp :: mvc model validation for decimal type 
Csharp :: last index for array c# 
Csharp :: update a file where there is a keyword c# 
Csharp :: Response.Redirect cannot be called in a Page callback 
Csharp :: do while loop in c# 
Csharp :: c# temporary files 
Csharp :: if statement in razor using "?" and ":" 
Csharp :: c# float min value 
Csharp :: StringFormat C# 
Csharp :: C# Async Function simple 
Csharp :: escape chars for regex c# 
Csharp :: C# assigning image location 
Csharp :: winforms combobox get selected text 
Csharp :: Using Linq to get the last N elements of a collection? C# 
Csharp :: c# linq join mutiple 
Csharp :: reference to gameobject in different scene unity 
Csharp :: camelCase and snakeCase 
Csharp :: list contains type c# 
Csharp :: c# sequential struct with fixed array size 
Csharp :: float into int unoity 
Csharp :: How to build a rest component with very long process 
Csharp :: list of vectors c# 
Csharp :: c# namespace name form1 could not be found 
Csharp :: custom attribute for auth permission check .net 
Csharp :: c# datagridview select row index programmatically 
Csharp :: psobject get service name 
ADD CONTENT
Topic
Content
Source link
Name
4+5 =