using System.Collections; using System.Collections.Generic; using UnityEngine; public class AnimatedWater : MonoBehaviour { public int rendererCounts; public float speedX = 0.1f; public float speedY = 0.1f; public bool is2Renderer; private float curX; private float curY; // Use this for initialization void Start () { curX = GetComponent().material.mainTextureOffset.x; curY = GetComponent().material.mainTextureOffset.y; } void FixedUpdate () { curX += Time.deltaTime * speedX; curY += Time.deltaTime * speedY; if (is2Renderer) { GetComponent().materials[1].SetTextureOffset("_MainTex", new Vector2(curX, curY)); GetComponent().materials[8].SetTextureOffset("_MainTex", new Vector2(curX, curY)); } else { GetComponent().materials[rendererCounts].SetTextureOffset("_MainTex", new Vector2(curX, curY)); } } }