RotateAndMove.cs 794 B

1234567891011121314151617181920212223242526272829303132
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. namespace Lux_SRP_GrassDisplacement
  5. {
  6. public class RotateAndMove : MonoBehaviour {
  7. public bool Rotate = true;
  8. public bool MoveUpDown = false;
  9. float posy;
  10. Transform trans;
  11. void OnEnable() {
  12. trans = this.GetComponent<Transform>();
  13. var pos = trans.position;
  14. posy = pos.y;
  15. }
  16. void Update() {
  17. if (Rotate) {
  18. trans.Rotate(0, 10.0f * Time.deltaTime, 0, Space.World);
  19. }
  20. if (MoveUpDown) {
  21. var pos = trans.position;
  22. pos.y = posy + 1.0f + Mathf.Sin(Time.time);
  23. trans.position = pos;
  24. }
  25. }
  26. }
  27. }