Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Astroid Script
- var astroidSpeed :float = 4.0;
- var explosion :Transform;
- var shieldExplosionAudio :AudioClip;
- var playerDamageAudio :AudioClip;
- var sceneManager :GameObject;
- //function OnTriggerEnter (other:Collider)
- function Update ()
- {
- /* OLD Rotation CODE
- //smoothly rotate the object around its Y axis at a rate of 20 degrees per second
- transform.RotateAround(transform.position, Vector3.up, 30 * Time.deltaTime);
- //smoothly rotate the object around its Y axis at a rate of 20 degrees per second
- transform.Rotate(transform.position, Vector3.left, 30 * Time.deltaTime);
- */
- // Slowly rotate the object around its X axis at 1 degree/second.
- transform.Rotate(Vector3.right, Time.deltaTime);
- // ... at the same time as spinning it relative to the global
- // Y axis at the same speed.
- transform.Rotate(Vector3.up, Time.deltaTime, Space.World);
- transform.Translate(Vector3.down * astroidSpeed * Time.deltaTime); //Move the object towards the bottom of the screen
- if(transform.position.y <= -6)
- {
- //Reset the position of the Astroid screen
- if(transform.position.y <= -6)
- {
- //Reset the position of the enemy
- ResetEnemy ();
- }
- }
- }
- //Check the collision event
- function OnTriggerEnter (other:Collider)
- {
- if(other.gameObject.tag == "Player")
- {
- other.GetComponent("Script Player").lives -= 1;
- //Tell scene manager that we lost a life
- sceneManager.transform.GetComponent("ScriptSceneManager").SubtractLife();
- if(explosion)
- {
- Instantiate (explosion, transform.position, transform.rotation);
- audio.clip = playerDamageAudio;
- audio.Play ();
- }
- //Reset the position of the enemy
- ResetEnemy ();
- // make the player blink + be immune for seconds set in inspector
- }
- if(other.gameObject.tag == "shield")
- {
- if(explosion)
- {
- Instantiate (explosion, transform.position, transform.rotation);
- audio.clip = shieldExplosionAudio;
- audio.Play ();
- }
- //Reset the position of the enemy
- ResetEnemy ();
- }
- }
- //funtion for moving the astroid object to a new starting point when it reaches the bottom of the screen (called during the
- function ResetEnemy ()
- {
- //Reset the position of the enemy
- transform.position.y = 8;
- transform.position.x = Random.Range (-6.0,6.0);
- }
Advertisement
Add Comment
Please, Sign In to add comment