Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* This script is licensed under the BSD license.
- Author: Cody Dostal
- Author Email: allysman21@gmail.com
- Date Written: 4/22/2012
- Date Last Edited: 4/24/2012
- Engine Version: 3.5.1f2
- Script Version: v1.1
- */
- /* NOTE: With good chance, you may have to change any hard-coded values in these scripts.
- These values work with my version, and may not with your version. */
- import UnityEngine
- class Enemy (MonoBehaviour):
- // Setting Minimum and Maximum speeds as Floats
- public MinSpeed as single = 0.0F
- public MaxSpeed as single = 0.0F
- public curSpeed as single = 0.0F
- private x as single = 0.0F
- private y as single = 0.0F
- private z as single = 0.0F
- // Variation in the meteors.
- private minRotateSpeed as single = 60f
- private maxRotateSpeed as single = 120f
- private MinScale as single = .8f
- private MaxScale as single = 2f
- private currentRotateSpeed as single = 0.0f
- private currentScaleX as single = 0.0f
- private currentScaleY as single = 0.0f
- private currentScaleZ as single = 0.0f
- // So the Powerups script knows how many meteors have fallen.
- public static curMeteorFallen as int // TO BE IMPLEMENTED
- // Set up explosionPrefab as GameObject. SET IN EDITOR
- public explosionPrefab as GameObject
- def Start ():
- // Setting Start Positions
- y = 4.8F
- z = 0.0F
- // Redirect to "def ranSpotSpeed():"
- ranSpotSpeed()
- def Update ():
- // Setting up the "animation." deltaTime sets the speed to real-world 1s.
- rotationSpeed as single = currentRotateSpeed * Time.deltaTime
- amtToMove = curSpeed * Time.deltaTime
- // Move DOWN the screen.
- transform.Translate(Vector3.down * amtToMove, Space.World)
- // Rotate on the X axis.
- transform.Rotate(Vector3(-1, 0, 0) * rotationSpeed)
- // In case the meteor goes off the bottom of the screen.
- if transform.position.y <= -7.5:
- // Incremenet the "Missed" variable in the player script up by 1.
- player.missed++
- // Check the player score. If it is greater than 0, decrement by 100, if it is lower than 0, set it to 0.
- if player.score > 0:
- player.score = player.score - 100
- elif player.score < 0:
- player.score = 0
- else:
- pass
- // Call ranSpotSpeed()
- ranSpotSpeed()
- def ranSpotSpeed():
- // Causing the variables to change the asteroids size/rotate speed.
- currentRotateSpeed = Random.Range(minRotateSpeed, maxRotateSpeed)
- currentScaleX = Random.Range(MinScale, MaxScale)
- currentScaleY = Random.Range(MinScale, MaxScale)
- currentScaleZ = Random.Range(MinScale, MaxScale)
- // Setting the x to be random from -5.5, and 5.5 on the screen.
- x = Random.Range(-5.5F, 5.5F)
- // Setting up the vector
- newPos = Vector3(x,y,z)
- // Setting the Enemy to start at newPos, our vector
- transform.position = newPos
- // Setting speed to be random between MinSpeed and MaxSpeed as set in the Editor
- curSpeed = Random.Range(MinSpeed, MaxSpeed)
- // Change the scale.
- transform.localScale = Vector3(currentScaleX, currentScaleY, currentScaleZ)
- // Increment the curMeteorFallen by 1. Will be used by Powerups to figure out when to fall.
- curMeteorFallen++
- // If something enters the collider, (must be PRIMITIVE collider, not MESH collider).
- def OnTriggerEnter(thisObject as Collider):
- // Call ranSpotSpeed to "rebuild" (although it is never actually destroyed) at the top.
- ranSpotSpeed()
- if MinSpeed > 7 and MaxSpeed > 13:
- pass
- else:
- MinSpeed += 0.1
- MaxSpeed += 0.1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement