CultPong/Assets/Scripts/TextureScroll.cs
2020-09-25 07:12:38 +01:00

28 lines
752 B
C#

using System.Collections;
using System.Collections.Generic;
using System.Xml;
#if UNITY_EDITOR
using UnityEditor;
#endif
using UnityEngine;
[ExecuteInEditMode]
public class TextureScroll : MonoBehaviour
{
public Vector2 TextureScrollSpeed;
private MeshRenderer _targetMesh;
private void OnWillRenderObject()
{
if(_targetMesh==null) _targetMesh = GetComponent<MeshRenderer>();
#if UNITY_EDITOR
float time = (float) EditorApplication.timeSinceStartup;
#else
float time = Time.time;
#endif
// Application.isPlaying ? Time.time : (float) EditorApplication.timeSinceStartup;
_targetMesh.sharedMaterial.mainTextureOffset = new Vector2(Mathf.Repeat(TextureScrollSpeed.x * time, 1), Mathf.Repeat(TextureScrollSpeed.y * time, 1));
}
}