Legacy Documentation: Version 2017.1 (Go to current version)
言語English
  • C#
  • JS

Script language

Select your preferred scripting language. All code snippets will be displayed in this language.

Material.GetTag

フィードバック

ありがとうございます

この度はドキュメントの品質向上のためにご意見・ご要望をお寄せいただき、誠にありがとうございます。頂いた内容をドキュメントチームで確認し、必要に応じて修正を致します。

閉じる

送信に失敗しました

なんらかのエラーが発生したため送信が出来ませんでした。しばらく経ってから<a>もう一度送信</a>してください。ドキュメントの品質向上のために時間を割いて頂き誠にありがとうございます。

閉じる

キャンセル

マニュアルに切り替える
public function GetTag(tag: string, searchFallbacks: bool, defaultValue: string = ""): string;
public string GetTag(string tag, bool searchFallbacks, string defaultValue = "");

説明

マテリアルのシェーダーのタグ名を取得します

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.

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 water uses this function to detect when the shader falls back to non-reflective one, and turns off reflection camera in that case.

// Attach this to a gameObject that has a renderer.

var materialTag = "RenderType";

function Start() { var rend = GetComponent.<Renderer>(); var result : String = rend.material.GetTag(materialTag, true, "Nothing");

if (result == "Nothing") Debug.LogError(materialTag + " not found in " + rend.material.shader.name); else Debug.Log("Tag found!, its value: " + result); }
using UnityEngine;
using System.Collections;

public class ExampleClass : MonoBehaviour { public string materialTag = "RenderType"; void Start() { Renderer rend = GetComponent<Renderer>(); string result = rend.material.GetTag(materialTag, true, "Nothing"); if (result == "Nothing") Debug.LogError(materialTag + " not found in " + rend.material.shader.name); else Debug.Log("Tag found!, its value: " + result); } }

Did you find this page useful? Please give it a rating: