Created
October 2, 2016 08:02
-
-
Save khoslaventures/1553d544207b16d6b9292509424f3f76 to your computer and use it in GitHub Desktop.
Unity Particle Sea, simple version. Apply to terrain and then hide terrain object, adjust camera. Done.
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
| using UnityEngine; | |
| using System.Collections; | |
| public class ParticleSeaSimple : MonoBehaviour { | |
| public ParticleSystem particleSystem; | |
| private ParticleSystem.Particle[] particlesArray; | |
| public Gradient colorGradient; | |
| public int seaResolution = 100; | |
| public float spacing = 1.0f; | |
| public float noiseScale = 0.05f; | |
| public float heightScale = 4f; | |
| private float perlinNoiseAnimX = 0.01f; | |
| private float perlinNoiseAnimY = 0.01f; | |
| void Start() { | |
| particlesArray = new ParticleSystem.Particle[seaResolution * seaResolution]; | |
| particleSystem.maxParticles = seaResolution * seaResolution; | |
| particleSystem.Emit(seaResolution * seaResolution); | |
| particleSystem.GetParticles(particlesArray); | |
| } | |
| void Update() { | |
| for(int i = 0; i < seaResolution; i++) { | |
| for(int j = 0; j < seaResolution; j++) { | |
| float zPos = Mathf.PerlinNoise(i * noiseScale + perlinNoiseAnimX, j * noiseScale + perlinNoiseAnimY); | |
| particlesArray[i * seaResolution + j].color = colorGradient.Evaluate(zPos); | |
| particlesArray[i * seaResolution + j].position = new Vector3(i * spacing, zPos * heightScale, j * spacing); | |
| } | |
| } | |
| perlinNoiseAnimX += 0.01f; | |
| perlinNoiseAnimY += 0.01f; | |
| particleSystem.SetParticles(particlesArray, particlesArray.Length); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment