Skip to content

Instantly share code, notes, and snippets.

@s2kw
Created March 13, 2016 12:18
Show Gist options
  • Save s2kw/7c85f77a31db7d8742a8 to your computer and use it in GitHub Desktop.
Save s2kw/7c85f77a31db7d8742a8 to your computer and use it in GitHub Desktop.
C#側からスクロールさせる
// 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