Advertisement
irishstorm

bngfvdsa

Mar 25th, 2013
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.23 KB | None | 0 0
  1.  
  2. // min and max times for type change
  3. public var minTypeChange : int = 10;
  4. public var maxTypeChange : int = 30;
  5.  
  6. //min and max rotatio speed
  7. public var minRotationSpeed : float = 0.5;
  8. public var maxRotationSpeed : float = 2.0;
  9.  
  10. //calculated rotation speed
  11. private var rotationSpeed : float;
  12.  
  13. //textfield to hold the score and score variable
  14. private var textfield : GUIText;
  15. private var score : int;
  16. public var Pickup : GameObject;
  17. private var SpawnPickup : GameObject;
  18. private var spawnIndexAvailableList;
  19. private var PickupCollected;
  20.  
  21. function UpdateScoreText()
  22. {
  23. //update textfield with score
  24. textfield.text = score.ToString();
  25. }
  26.  
  27. function Update()
  28. {
  29. // rotate the gameobject every frame
  30. transform.Rotate(rotationSpeed, rotationSpeed, 0);
  31. }
  32.  
  33. function Start()
  34. {
  35. while (true)
  36. {
  37. //wait for x seconds
  38. yield WaitForSeconds(Random.Range(minTypeChange, maxTypeChange));
  39. // set a random type
  40. SwapType();
  41. }
  42. }
  43.  
  44. function Awake()
  45. {
  46. textfield = GameObject.Find("GUI/txt-Score").GetComponent(GUIText);
  47. score = 0;
  48. UpdateScoreText();
  49.  
  50. // calculate a random rotation speed
  51. rotationSpeed = Random.Range(minRotationSpeed, maxRotationSpeed);
  52.  
  53. // set a random type to begin
  54. SwapType();
  55. }
  56.  
  57. function SwapType()
  58. {
  59. // generate a random number between 1 and 10
  60. var random : float = Random.Range(1, 10);
  61.  
  62. // set the type
  63. if (random <= 5) // 50% for type 1
  64. {
  65. type = 1;
  66. }
  67.  
  68. else if (random <= 8) // 30% for type 2
  69. {
  70. type = 2;
  71. }
  72.  
  73. else // 20% for type 3
  74. {
  75. type = 3;
  76. }
  77. }
  78.  
  79. function Collected(PickUpCollected : GameObject)
  80. {
  81. // retrieve name of the collected pick up and cast int
  82. var index : int = parseInt(PickUpCollected.name);
  83.  
  84. //retrieve the pickup state
  85. var type : int = PickUpCollected.GetComponent(PickUp).type;
  86.  
  87. //update the score depending on the type pickup
  88. if (type == 1)
  89. {
  90. score += 2; // add 2 to the score
  91. }
  92.  
  93. else if (type == 2)
  94. {
  95. score += Random.Range(-2, 5); // add a random score between -2 and 5 to score
  96. }
  97.  
  98. // update the score
  99. UpdateScoreText();
  100.  
  101. // Adds Score, when the object is collected.
  102. ApplyScore(10);
  103.  
  104. // destroy the pickup
  105. Destroy(PickUpCollected);
  106. }
  107.  
  108. function ApplyScore(score : int)
  109. {
  110. Score += score;
  111. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement