Version: 2023.1

Material.SetTextureOffset

切换到手册
public void SetTextureOffset (string name, Vector2 value);
public void SetTextureOffset (int nameID, Vector2 value);

参数

nameID 属性名称 ID,使用 Shader.PropertyToID 获取。
name The name of the texture property as defined in the shader. For example: "_MainTex".
value 纹理位置偏移。

描述

Sets the placement offset of a given texture. The name parameter is defined in the shader. This method creates a new Material instance.

另请参阅:mainTextureOffset 属性、GetTextureOffsetSetTexture

using UnityEngine;

public class Example : MonoBehaviour { // Scroll main texture based on time

float scrollSpeed = 0.5f; Renderer rend;

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

void Update() { float offset = Time.time * scrollSpeed; rend.material.SetTextureOffset("_TextureName", new Vector2(offset, 0)); } }