using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Pulse : MonoBehaviour
{
public float Lobes = 10;
public float TimeScale = 1;
public float Amount = 0.6f;
private Mesh mesh;
private Vector3[] originalPoints;
private Vector3[] originalNormals;
private Vector3[] points;
// Start is called before the first frame update
void Start()
{
MeshFilter mf = GetComponent<MeshFilter>();
//mesh = GameObject.Instantiate(mf.mesh);
//mf.mesh = mesh;
mesh = mf.mesh;
mesh.RecalculateNormals();
originalPoints = mesh.vertices;
originalNormals = mesh.normals;
points = new Vector3[originalPoints.Length];
}
// Update is called once per frame
void Update()
{
for (int i = 0; i < originalPoints.Length; i++)
{
Vector3 o = originalPoints[i];
Vector3 n = originalNormals[i];
float angleUp = Mathf.Atan2(new Vector2(o.x, o.z).magnitude, o.y);
float expand = Mathf.Sin(Mathf.Atan2(o.x, o.z) * Mathf.Round(Lobes * angleUp) * Mathf.Sin(angleUp * Lobes) + Time.realtimeSinceStartup * Mathf.PI * TimeScale) * Amount;
points[i] = o + n * expand;
}
mesh.vertices = points;
mesh.RecalculateNormals();
mesh.RecalculateBounds();
}
}