Version: 2017.1

MonoBehaviour.OnWillRenderObject()

切换到手册

描述

如果对象可见,则为每个摄像机调用 OnWillRenderObject。

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

该函数在剔除处理期间(即将渲染每个剔除的对象时)调用。 如需了解在适当上下文中的用法,请参阅 Assets > Import Package > Effects 中的脚本 /Water.cs/。

Note that Camera.current will be set to the camera that will render the object.

using UnityEngine;
using System.Collections;

public class ExampleClass : MonoBehaviour { public Renderer rend; void Start() { rend = GetComponent<Renderer>(); } void OnWillRenderObject() { if (Camera.current.name == "MiniMapcam") rend.material.color = Color.red; else rend.material.color = Color.white; } }

Also, this is called multiple times per frame.