vjanomolee

Asteroid Script

Aug 18th, 2011
245
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //Astroid Script
  2.  
  3. var astroidSpeed            :float = 4.0;
  4. var explosion               :Transform;
  5.  
  6. var shieldExplosionAudio    :AudioClip;
  7. var playerDamageAudio       :AudioClip;
  8. var sceneManager            :GameObject;
  9. //function OnTriggerEnter (other:Collider)
  10.  
  11. function Update ()
  12. {
  13. /* OLD Rotation CODE
  14.  
  15.     //smoothly rotate the object around its Y axis at a rate of 20 degrees per second
  16.     transform.RotateAround(transform.position, Vector3.up, 30 * Time.deltaTime);
  17.    
  18.     //smoothly rotate the object around its Y axis at a rate of 20 degrees per second
  19.     transform.Rotate(transform.position, Vector3.left, 30 * Time.deltaTime);
  20. */
  21.  
  22.    // Slowly rotate the object around its X axis at 1 degree/second.
  23.     transform.Rotate(Vector3.right, Time.deltaTime);
  24.  
  25.     // ... at the same time as spinning it relative to the global
  26.     // Y axis at the same speed.
  27.     transform.Rotate(Vector3.up, Time.deltaTime, Space.World);
  28.  
  29.    
  30.    
  31.     transform.Translate(Vector3.down * astroidSpeed * Time.deltaTime);  //Move the object towards the bottom of the screen
  32.    
  33.     if(transform.position.y <= -6)
  34.     {
  35.         //Reset the position of the Astroid screen
  36.         if(transform.position.y <= -6)
  37.         {
  38.             //Reset the position of the enemy
  39.             ResetEnemy ();
  40.         }
  41.     }
  42. }
  43.  
  44. //Check the collision event
  45. function OnTriggerEnter (other:Collider)
  46. {
  47.     if(other.gameObject.tag == "Player")
  48.     {
  49.             other.GetComponent("Script Player").lives -= 1;
  50.            
  51.             //Tell scene manager that we lost a life
  52.             sceneManager.transform.GetComponent("ScriptSceneManager").SubtractLife();
  53.             if(explosion)
  54.             {
  55.             Instantiate (explosion, transform.position, transform.rotation);
  56.             audio.clip = playerDamageAudio;
  57.             audio.Play ();
  58.             }          
  59.             //Reset the position of the enemy
  60.             ResetEnemy ();
  61.            
  62.             // make the player blink + be immune for seconds set in inspector
  63.        
  64.     }
  65.    
  66.     if(other.gameObject.tag == "shield")
  67.     {
  68.         if(explosion)
  69.         {
  70.             Instantiate (explosion, transform.position, transform.rotation);
  71.             audio.clip = shieldExplosionAudio;
  72.             audio.Play ();
  73.         }
  74.        
  75.         //Reset the position of the enemy
  76.         ResetEnemy ();
  77.     }
  78. }
  79.  
  80. //funtion for moving the astroid object to a new starting point when it reaches the bottom of the screen (called during the
  81. function ResetEnemy ()
  82. {
  83.     //Reset the position of the enemy
  84.     transform.position.y = 8;
  85.     transform.position.x = Random.Range (-6.0,6.0);
  86. }
Advertisement
Add Comment
Please, Sign In to add comment