Version: 2023.2

MonoBehaviour.OnWillRenderObject()

切换到手册

描述

如果对象可见并且不是 UI 元素,则为每个摄像机调用 OnWillRenderObject。

如果禁用了 MonoBehaviour,则不会调用该函数。

The function is called during the culling process just before rendering each culled object.

注意,Camera.current 设置为将渲染该对象的摄像机。

**注意:**从 UI 元素调用时无效。

using UnityEngine;
using System.Collections;

public class ExampleScript : MonoBehaviour { public Renderer rend;

private float timePass = 0.0f;

void Start() { rend = GetComponent<Renderer>(); }

void OnWillRenderObject() { timePass += Time.deltaTime;

if (timePass > 1.0f) { timePass = 0.0f; print(gameObject.name + " is being rendered by " + Camera.current.name + " at " + Time.time); } } }

每帧将调用多次。