UnityのMaterialのTilingやOffsetの値をスクリプトから変更する方法

SetTextureOffsetSetTextureScaleを使うことで、MaterialのTilingやOffsetの値を変更できるようです。

使い方は次のような感じです。

Renderer renderer = GetComponent<Renderer> ();

Vector2 offset = new Vector2(...);
Vector2 scale = new Vector2(...);

renderer.material.SetTextureOffset("_MainTex", offset);
renderer.material.SetTextureScale("_MainTex", scale);
renderer.material.SetTextureOffset("_BumpMap", offset);
renderer.material.SetTextureScale("_BumpMap", scale);

リンク

How to change Tiling / Offset of all generated Textures by script?
https://forum.allegorithmic.com/index.php?topic=3077.0

Unity 2017.3

Unity 2017.3がリリースされました。

Unity – What’s new in Unity 2017.3
https://unity3d.com/unity/whats-new/unity-2017.3.0

VR/AR関連、Graphics関連、Particles関連等の機能追加や実装改善が行われているとのこと。

ブログでも内容が紹介されています。

Unity 2017.3がリリースされました! – Unity Blog
https://blogs.unity3d.com/jp/2017/12/19/unity-2017-3-is-here/

Unity Editorからのデバッグ時のみ実行するifdef

UNITY_EDITORを使うと、Unity Editorでのデバッグ時のみ実行するコードを書けるようです。

使い方は次のような感じです。

#if UNITY_EDITOR
Debug.log("debug");
#endif

他、UNITY_ANDROIDUNITY_IPHONE等も便利そうです。

リンク

Unity – Platform Dependent Compilation
https://docs.unity3d.com/351/Documentation/Manual/PlatformDependentCompilation.html