お好みのスクリプト言語を選択すると、サンプルコードがその言語で表示されます。
Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.
Closeマテリアルのテクスチャ
これは GetTexture や "_MainTex"
を使用しての SetTexture と同じ動作をします。
See Also: SetTexture, GetTexture.
// Assign the texture exposed in the inspector the renderer's material var texture : Texture; renderer.material.mainTexture = texture;
using UnityEngine; using System.Collections; public class ExampleClass : MonoBehaviour { public Texture texture; void Example() { renderer.material.mainTexture = texture; } }
import UnityEngine import System.Collections public class ExampleClass(MonoBehaviour): public texture as Texture def Example() as void: renderer.material.mainTexture = texture
他の例:
// Change renderer's texture each changeInterval/
// seconds from the texture array defined in the inspector.
var textures : Texture[];
var changeInterval : float = 0.33;
function Update() {
if( textures.length == 0 ) // nothing if no textures
return;
// we want this texture index now
var index : int = Time.time / changeInterval;
// take a modulo with size so that animation repeats
index = index % textures.length;
// assign it
renderer.material.mainTexture = textures[index];
}
using UnityEngine; using System.Collections; public class ExampleClass : MonoBehaviour { public Texture[] textures; public float changeInterval = 0.33F; void Update() { if (textures.length == 0) return; int index = Time.time / changeInterval; index = index % textures.length; renderer.material.mainTexture = textures[index]; } }
import UnityEngine import System.Collections public class ExampleClass(MonoBehaviour): public textures as (Texture) public changeInterval as float = 0.33F def Update() as void: if textures.length == 0: return index as int = (Time.time / changeInterval) index = (index % textures.length) renderer.material.mainTexture = textures[index]