Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2017
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.73 KB | None | 0 0
  1. private GameObject myobject;
  2. public float timeElapsed =0;
  3. public float delay = 3.0f;
  4. float OO = 0.0f;
  5.  
  6. void Start () {
  7. myobject = GameObject.Find ("rightarm").gameObject;
  8. }
  9.  
  10. void Update () {
  11. timeElapsed += Time.deltaTime;
  12. Debug.Log (timeElapsed);
  13.  
  14. if (timeElapsed >= delay) {
  15. OO = 30.0f;
  16. timeElapsed = 0;
  17. if (myobject.renderer.enabled == false) {
  18. myobject.renderer.enabled = true;
  19. }
  20.  
  21. myobject.transform.Rotate (OO, 0.0f, 0.0f);
  22. }
  23. else
  24. {
  25. myobject.transform.Rotate (-OO,0.0f, 0.0f );
  26. }
  27. }
  28.  
  29. void Update () {
  30. timeElapsed += Time.deltaTime;
  31. Debug.Log (timeElapsed);
  32.  
  33. if (timeElapsed >= delay) {
  34. OO = 30.0f;
  35. timeElapsed = 0;
  36. if (myobject.renderer.enabled == false) {
  37. myobject.renderer.enabled = true;
  38. }
  39.  
  40. myobject.transform.rotation = Quaternion.Euler (OO, 0.0f, 0.0f);
  41. }
  42. else
  43. {
  44. myobject.transform.rotation = Quaternion.Euler (-OO, 0.0f, 0.0f);
  45. }
  46.  
  47. // Specify how many degrees you want to rotate from the initial orientation.
  48. public Vector3 amplitude = new Vector3(30, 0, 0);
  49.  
  50. // Specify how many seconds a complete loop should take.
  51. public float period = 6f;
  52.  
  53. // Cache initial orientation so we can rotate relative to that pose.
  54. Quaternion _initialOrientation;
  55.  
  56. // Perform caching on Start.
  57. void Start() {
  58. _initialOrientation = transform.localRotation;
  59. }
  60.  
  61. void Update() {
  62. // Calculate how far along we should be in the wave.
  63. float phase = Mathf.PI * 2f * Time.time/period;
  64.  
  65. // Calculate the angle at this part of the wave.
  66. Vector3 angle = amplitude * Mathf.Cos(phase);
  67.  
  68. // Rotate by angle relative to our initial orientation.
  69. transform.localRotation = _initialOrientation * Quaternion.Euler(angle);
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement