Created
March 13, 2016 12:18
-
-
Save s2kw/7c85f77a31db7d8742a8 to your computer and use it in GitHub Desktop.
C#側からスクロールさせる
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// namespace jigaX{ | |
public class UVScroller : MonoBehaviour { | |
[SerializeField] List<Renderer> targetRenderers; | |
[SerializeField] Vector2 speed = new Vector2(); | |
List<Material> mats; | |
void Start () { | |
this.mats = new List<Material>(); | |
foreach(var r in this.targetRenderers ){ | |
foreach( var m in r.materials ){ | |
this.mats.Add(m); | |
} | |
} | |
} | |
Vector2 current; | |
const string MAIN_TEX = "_MainTex"; | |
const string EMISSION_TEX = "_EmissionMap"; | |
// Update is called once per frame | |
void Update () { | |
current += this.speed * Time.deltaTime; | |
if( current.x > 1f ){ current.x -= 1f;} | |
if( current.y > 1f ){ current.y -= 1f;} | |
if( current.x < -1f ){ current.x += 1f;} | |
if( current.y < -1f ){ current.y += 1f;} | |
foreach( var m in this.mats ){ | |
m.SetTextureOffset(MAIN_TEX, current); | |
m.SetTextureOffset(EMISSION_TEX, current); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment