Advertisement
pivotraze

Powerup Script

Dec 2nd, 2012
346
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
BOO 2.42 KB | None | 0 0
  1. /* This script is licensed under the BSD license.
  2. Author: Cody Dostal
  3. Author Email: allysman21@gmail.com
  4. Date Written: 4/22/2012
  5. Date Last Edited: 4/24/2012
  6. Engine Version: 3.5.1f2
  7. Script Version: v1.1
  8. */
  9.  
  10. /* NOTE: With good chance, you may have to change any hard-coded values in these scripts.
  11. These values work with my version, and may not with your version. */
  12.  
  13. import UnityEngine
  14.  
  15. class Powerups (MonoBehaviour):
  16.    
  17.     // Setting Minimum and Maximum speeds as Floats
  18.     public MinSpeed as single = 0.0F
  19.     public MaxSpeed as single = 0.0F
  20.  
  21.     private curSpeed as single = 0.0F
  22.     private x as single = 0.0F
  23.     private y as single = 0.0F
  24.     private z as single = 0.0F
  25.  
  26.  
  27.     // Variation in the meteors.
  28.     private minRotateSpeed as single = 60f
  29.     private maxRotateSpeed as single = 120f
  30.     private currentRotateSpeed as single = 0.0f
  31.    
  32.     // Set up explosionPrefab as GameObject. SET IN EDITOR
  33.     public explosionPrefab as GameObject
  34.    
  35.     def Start ():
  36.         // Setting Start Positions
  37.         y = 4.8F
  38.         z = 0.0F
  39.  
  40.         // Redirect to "def ranSpotSpeed():"
  41.         ranSpotSpeed()
  42.  
  43.     def Update ():
  44.         if Enemy.curMeteorFallen >= 12:
  45.             // Setting up the "animation." deltaTime sets the speed to real-world 1s.
  46.             rotationSpeed as single = currentRotateSpeed * Time.deltaTime
  47.             amtToMove = curSpeed * Time.deltaTime
  48.            
  49.         // Move DOWN the screen.
  50.         transform.Translate(Vector3.down * amtToMove, Space.World)
  51.         // Rotate on the X axis.
  52.         transform.Rotate(Vector3(-1, 0, 0) * rotationSpeed)
  53.    
  54.         // In case the meteor goes off the bottom of the screen.
  55.         if transform.position.y <= -7.5:
  56.             // Call ranSpotSpeed()
  57.             ranSpotSpeed()
  58.             Enemy.curMeteorFallen = 0
  59.  
  60.     def ranSpotSpeed():
  61.        
  62.         // Causing the variables to change the asteroids size/rotate speed.
  63.         currentRotateSpeed = Random.Range(minRotateSpeed, maxRotateSpeed)
  64.         // Setting the x to be random from -5.5, and 5.5 on the screen.
  65.         x = Random.Range(-5.5F, 5.5F)
  66.         // Setting up the vector
  67.         newPos = Vector3(x,y,z)
  68.         // Setting the Enemy to start at newPos, our vector
  69.         transform.position = newPos
  70.         // Setting speed to be random between MinSpeed and MaxSpeed as set in the Editor
  71.         curSpeed = Random.Range(MinSpeed, MaxSpeed)
  72.  
  73.     // If something enters the collider, (must be PRIMITIVE collider, not MESH collider).
  74.     def OnTriggerEnter(thisObject as Collider):
  75.         // Call ranSpotSpeed to "rebuild" (although it is never actually destroyed) at the top.
  76.         ranSpotSpeed()
  77.         Enemy.curMeteorFallen = 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement