fxvSinPos.cs 1012 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. namespace FXV.FogDemo
  5. {
  6. public class fxvSinPos : MonoBehaviour
  7. {
  8. public bool random = false;
  9. public float amplitude = 2.0f;
  10. public float speed = 1.0f;
  11. private Vector3 startPos;
  12. private float angle = 0.0f;
  13. Vector3 direction = Vector3.up;
  14. void Start()
  15. {
  16. startPos = transform.position;
  17. if (random)
  18. {
  19. amplitude = Random.Range(0, amplitude);
  20. speed = Random.Range(0, speed);
  21. angle = Random.Range(0, Mathf.PI * 2.0f);
  22. direction = Random.insideUnitSphere.normalized;
  23. }
  24. }
  25. void Update()
  26. {
  27. angle += Time.deltaTime * speed;
  28. if (angle > Mathf.PI * 2.0f)
  29. angle -= Mathf.PI * 2.0f;
  30. transform.position = startPos + direction * Mathf.Sin(angle) * amplitude;
  31. }
  32. }
  33. }