Advertisement
Guest User

Untitled

a guest
Apr 19th, 2014
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.58 KB | None | 0 0
  1. int dir = 1; // somewhere global
  2.  
  3. Quaternion r = Quaternion.Euler(0, Timer.deltaTime * dir, 0);
  4.  
  5. transform.rotation *= r;
  6.  
  7. // I want to: if the "angle is >= 5f", i want to do dir *= -1 to reverse it
  8.  
  9. if (/* angle delta is >= 5f or <= -5f */)
  10. {
  11. dir *= -1;
  12. }
  13.  
  14. public class rotator : MonoBehaviour {
  15.  
  16. public float _Angle;
  17. public float _Period;
  18.  
  19. private float _Time;
  20.  
  21. // Update is called once per frame
  22. void Update () {
  23. _Time = _Time + Time.deltaTime;
  24. float phase = Mathf.Sin(_Time / _Period);
  25. transform.localRotation = Quaternion.Euler( new Vector3(0, phase * _Angle, 0));
  26. }
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement