using System.Collections; using UnityEngine; public class PPFXShockwave : MonoBehaviour { public enum Axis { up = 0, down = 1, left = 2, right = 3, forward = 4, back = 5 } private Camera referenceCamera; public bool reverseFace; public Axis axis; private float duration; public float scale; public bool loop; public bool lookAt; public Vector3 GetAxis(Axis refAxis) { switch (refAxis) { case Axis.down: return Vector3.down; case Axis.forward: return Vector3.forward; case Axis.back: return Vector3.back; case Axis.left: return Vector3.left; case Axis.right: return Vector3.right; default: return Vector3.up; } } private void Awake() { if (!referenceCamera) { referenceCamera = Camera.main; } StartCoroutine(StartAnimation()); } private void Update() { if (lookAt) { Vector3 worldPosition = base.transform.position + referenceCamera.transform.rotation * ((!reverseFace) ? Vector3.back : Vector3.forward); Vector3 worldUp = referenceCamera.transform.rotation * GetAxis(axis); base.transform.LookAt(worldPosition, worldUp); } } private IEnumerator StartAnimation() { base.transform.localScale = new Vector3(0f, 0f, 0f); base.transform.GetComponent().material.SetColor("_TintColor", new Color(1f, 1f, 1f, 1f)); StartCoroutine(Animate()); yield return null; } private IEnumerator Animate() { float t = 0f; while (t < 1f) { base.transform.localScale = new Vector3(Mathf.Lerp(0f, scale, t / 0.5f), Mathf.Lerp(0f, scale, t / 0.5f), Mathf.Lerp(0f, scale, t / 0.5f)); base.transform.GetComponent().material.SetColor("_TintColor", Color.Lerp(new Color(1f, 1f, 1f, 1f), new Color(1f, 1f, 1f, 0f), t / 0.5f)); t += Time.deltaTime; yield return null; } } }