1 using System;
2 using
UnityEngine;
3
4 namespace
UnityStandardAssets.Water
5 {
6     
[ExecuteInEditMode]
7     
public class WaterBasic : MonoBehaviour
8     {
9         
void Update()
10         {
11             Renderer r = GetComponent<Renderer>();
12             
if (!r)
13             {
14                 
return;
15             }
16             Material mat = r.sharedMaterial;
17             
if (!mat)
18             {
19                 
return;
20             }
21
22             Vector4 waveSpeed = mat.GetVector(
"WaveSpeed");
23             
float waveScale = mat.GetFloat("_WaveScale");
24             
float t = Time.time / 20.0f;
25
26             Vector4 offset4 = waveSpeed * (t * waveScale);
27             Vector4 offsetClamped =
new Vector4(Mathf.Repeat(offset4.x, 1.0f), Mathf.Repeat(offset4.y, 1.0f),
28                 Mathf.Repeat(offset4.z,
1.0f), Mathf.Repeat(offset4.w, 1.0f));
29             mat.SetVector(
"_WaveOffset", offsetClamped);
30         }
31     }
32 }


Tìm kiếm mở rộng