Material.GetTag 获取标签

function GetTag (tag : string, searchFallbacks : bool, defaultValue : string = "") : string


Get the value of material's shader tag.


If the material's shader does not define the tag, defaultValue is returned.


If searchFallbacks is true then this function will look for tag in all subshaders and all fallbacks.If seachFallbacks is false then only the currently used subshader will be queried for the tag.

如果 searchFallbacks 是true此函数将查找所有的子级着色器(subshader)和所有的后备标签。如果 seachFallbacks 是false此函数仅在当前使用的子级着色器(subshader)中查询标签。

Using GetTag without searching through fallbacks makes it possible to detect which subshader is currently being used: add a custom tag to each subshader with different value, and query the value at run time. For example, Unity Pro's water uses this function to detect when the shader falls back to non-reflective one, and turns off reflection camera in that case.

使用没有后备搜索的GetTag,检测当前正在使用的子级着色器(subshader): 将一个自定义的标签添加到每个具有不同的值的子级着色器(subshader)和查询在运行时的值。例如unity专业版的水,检测着色器何时将退化为于无反射,并使用此函数在这种情况下关闭反射相机。

using UnityEngine;
using System.Collections;

public class example : MonoBehaviour {
	public string materialTag = "RenderType";
	void Start() {
		string result = renderer.material.GetTag(materialTag, true, "Nothing");
		if (result == "Nothing")
			Debug.LogError(materialTag + " not found in " +;
			Debug.Log("Tag found!, its value: " + result);
// Attach this to a gameObject that has a renderer

var materialTag = "RenderType";
function Start() {
	var result : String = renderer.material.GetTag(materialTag, true, "Nothing");
	if (result == "Nothing")
		Debug.LogError (materialTag + " not found in " +;
		Debug.Log ("Tag found!, its value: " + result);
Page last updated: 2011-1-22