Advertisement
pivotraze

Enemy Script

Dec 2nd, 2012
379
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
BOO 3.44 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 Enemy (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.     public 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 MinScale as single = .8f
  31.     private MaxScale as single = 2f
  32.     private currentRotateSpeed as single = 0.0f
  33.     private currentScaleX as single = 0.0f
  34.     private currentScaleY as single = 0.0f
  35.     private currentScaleZ as single = 0.0f
  36.    
  37.     // So the Powerups script knows how many meteors have fallen.
  38.     public static curMeteorFallen as int // TO BE IMPLEMENTED
  39.    
  40.     // Set up explosionPrefab as GameObject. SET IN EDITOR
  41.     public explosionPrefab as GameObject
  42.  
  43.  
  44.     def Start ():
  45.         // Setting Start Positions
  46.         y = 4.8F
  47.         z = 0.0F
  48.  
  49.         // Redirect to "def ranSpotSpeed():"
  50.         ranSpotSpeed()
  51.  
  52.     def Update ():
  53.        
  54.         // Setting up the "animation." deltaTime sets the speed to real-world 1s.
  55.         rotationSpeed as single = currentRotateSpeed * Time.deltaTime
  56.         amtToMove = curSpeed * Time.deltaTime
  57.        
  58.         // Move DOWN the screen.
  59.         transform.Translate(Vector3.down * amtToMove, Space.World)
  60.         // Rotate on the X axis.
  61.         transform.Rotate(Vector3(-1, 0, 0) * rotationSpeed)
  62.  
  63.         // In case the meteor goes off the bottom of the screen.
  64.         if transform.position.y <= -7.5:
  65.             // Incremenet the "Missed" variable in the player script up by 1.
  66.             player.missed++
  67.            
  68.             // Check the player score. If it is greater than 0, decrement by 100, if it is lower than 0, set it to 0.
  69.             if player.score > 0:
  70.                 player.score = player.score - 100
  71.             elif player.score < 0:
  72.                 player.score = 0
  73.             else:
  74.                 pass
  75.                
  76.             // Call ranSpotSpeed()
  77.             ranSpotSpeed()
  78.  
  79.     def ranSpotSpeed():
  80.        
  81.         // Causing the variables to change the asteroids size/rotate speed.
  82.         currentRotateSpeed = Random.Range(minRotateSpeed, maxRotateSpeed)
  83.         currentScaleX = Random.Range(MinScale, MaxScale)
  84.         currentScaleY = Random.Range(MinScale, MaxScale)
  85.         currentScaleZ = Random.Range(MinScale, MaxScale)
  86.         // Setting the x to be random from -5.5, and 5.5 on the screen.
  87.         x = Random.Range(-5.5F, 5.5F)
  88.         // Setting up the vector
  89.         newPos = Vector3(x,y,z)
  90.         // Setting the Enemy to start at newPos, our vector
  91.         transform.position = newPos
  92.         // Setting speed to be random between MinSpeed and MaxSpeed as set in the Editor
  93.         curSpeed = Random.Range(MinSpeed, MaxSpeed)
  94.  
  95.         // Change the scale.
  96.         transform.localScale = Vector3(currentScaleX, currentScaleY, currentScaleZ)
  97.        
  98.         // Increment the curMeteorFallen by 1. Will be used by Powerups to figure out when to fall.
  99.         curMeteorFallen++
  100.  
  101.     // If something enters the collider, (must be PRIMITIVE collider, not MESH collider).
  102.     def OnTriggerEnter(thisObject as Collider):
  103.         // Call ranSpotSpeed to "rebuild" (although it is never actually destroyed) at the top.
  104.         ranSpotSpeed()
  105.         if MinSpeed > 7 and MaxSpeed > 13:
  106.             pass
  107.         else:
  108.             MinSpeed += 0.1
  109.             MaxSpeed += 0.1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement