Advertisement
pivotraze

Projectile Script

Dec 2nd, 2012
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
BOO 1.92 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 projectile (MonoBehaviour):
  16.    
  17.     public projSpeed as single = 0.0F
  18.  
  19.     public explosionPrefab as GameObject
  20.    
  21.     def Update ():
  22.         // Set the speed (projSpeed... set in editor) and use deltaTime to make it in 1 sec.
  23.         amtToMove = projSpeed * Time.deltaTime
  24.         // Cause bullet to go UP screen.
  25.         transform.Translate(Vector3.up * amtToMove)
  26.  
  27.         // Destroy the projectile if it goes off screen.
  28.         if transform.position.y >= 3.65:
  29.             Destroy(gameObject)
  30.  
  31.    
  32.     def OnTriggerEnter(otherObject as Collider):
  33.         // So the bullet does NOT collide with the player. Tag on player gameObject MUST BE SET to Player.
  34.         if otherObject.tag != "Player":
  35.             if otherObject.tag == "Enemy":
  36.                 // Set Explosion position, and Instantiate(create) it
  37.                 exploPos = Vector3(transform.position.x, transform.position.y, transform.position.z)
  38.                 Instantiate(explosionPrefab, exploPos, Quaternion.identity)
  39.            
  40.                 // Destroy the projectile if it hits the enemy.
  41.                 Destroy(gameObject)
  42.                
  43.                 // Increase the player score for each Enemy hit.
  44.                 if player.score < 5000:
  45.                     player.score += 100
  46.            
  47.             if otherObject.tag == "health":
  48.                 exploPos = Vector3(transform.position.x, transform.position.y, transform.position.z)
  49.                 Instantiate(explosionPrefab, exploPos, Quaternion.identity)
  50.                 player.lives++
  51.                 Destroy(gameObject)
  52.                
  53.             // If player.score is equal to 5000pts
  54.             if player.score >= 5000:
  55.                 // Wait for 2 seconds to finish the last explosion animation.
  56.                 WaitForSeconds(2.0F)
  57.                 // Load the win screen.
  58.                 Application.LoadLevel(3)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement