Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2014
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.61 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class BALL : MonoBehaviour {
  5.  
  6. public float InitialForce = 100f;
  7. Vector3 initVelocity = new Vector3();
  8.  
  9. void Start()
  10. {
  11.  
  12. Launch ();
  13.  
  14. }
  15.  
  16. // Use this for initialization
  17. void Launch ()
  18. {
  19.  
  20.  
  21. initVelocity.x = Random.Range(-1f,1f);
  22. initVelocity.y = Random.Range(-1f,1f);
  23. initVelocity.Normalize ();
  24.  
  25. if
  26.  
  27. (Mathf.Abs (initVelocity.x) < Mathf.Abs(initVelocity.y))
  28.  
  29. {
  30. float x = initVelocity.x ;
  31. initVelocity.x = initVelocity.y ;
  32. initVelocity.y = x;
  33.  
  34. }
  35.  
  36.  
  37. rigidbody.AddForce(initVelocity * InitialForce);
  38.  
  39. }
  40.  
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement