unity3d - 获取另一个游戏对象的渲染器
问题描述
我有一个带有未点亮\透明纹理的 3d 立方体。我正在尝试访问材质偏移参数。
public class scroll : MonoBehaviour {
public float speed = 0.5f;
public GameObject stars, bg;
public Component ren;
// Use this for initialization
void Start () {
ren = GameObject.Find("stars").GetComponent<Renderer>();
}
// Update is called once per frame
void Update () {
Vector2 offset = new Vector2(0, Time.time * speed);
//here I want to change offset of the texture (shader: unlit\transparent)
}
}
我试过了
ren.renderer.material.mainTextureOffeset = offset;
得到一个错误:
UnityEngine.Material
不包含定义, 也找不到类型的mainTextureOffeset
扩展方法。您是否缺少程序集参考?mainTextureOffeset
UnityEngine.Material
结构体:
-WORLD(此脚本附在此处)
--stars(3D立方体)
解决方案
您的代码中有错字:mainTextureOffeset
而不是mainTextureOffset
. 我没有看到任何其他UnityEngine.Material
不包含 的可能性mainTextureOffset
。