1. Help us improve the editor usability and artist workflows. Join our discussion to provide your feedback.
    Dismiss Notice
  2. Unity 5.6 is now released.
    Dismiss Notice
  3. Check out all the fixes for 5.5 in patch releases 1 & 2.
    Dismiss Notice
  4. Get further faster with the Unity Plus Accelerator Pack, free for new Unity Plus subscribers for a limited time. Click here for more details.
    Dismiss Notice
  5. Learn how you'll soon be able to publish your games to China in four simple steps with Xiaomi. Sign up now for early access.
    Dismiss Notice

Shake an object from script

Discussion in 'Scripting' started by FootprintGames, Jun 2, 2012.

  1. FootprintGames

    FootprintGames

    Joined:
    Mar 6, 2012
    Posts:
    303
    There's someone who can help me shaking an object using script?
     
  2. flaminghairball

    flaminghairball

    Joined:
    Jun 12, 2008
    Posts:
    862
    Code (csharp):
    1.  
    2. var speed = 1.0f; //how fast it shakes
    3. var amount = 1.0f; //how much it shakes
    4.  
    5. function Update()
    6. {
    7.   transform.position.x = Mathf.Sin(Time.time * speed);
    8. }
    9.  
     
  3. harko12

    harko12

    Joined:
    Jul 6, 2012
    Posts:
    3
    Worked great for me, Thanks!