Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Missle Script
- var heightLimit =10.0;
- var explosion :Transform;
- var sceneManager :GameObject;
- var missileExplodeSound :AudioClip;
- var missileSpeed =5.0;
- var targetTag :String; //This is so you can change what tag is the target in the inspector instead of the script
- var missileTargets :Transform[];
- function Update () //Game Loop runs every frame
- {
- var tar = GameObject.FindWithTag(targetTag);
- if(tar)
- {
- var randomTarget = missileTargets[Random.Range(0, missileTargets.Length -1)];
- transform.LookAt(randomTarget);
- transform.Translate(Vector3.forward*missileSpeed*Time.deltaTime);
- }
- if(transform.position.y >= heightLimit) //check if the object is off screen
- {
- Destroy(gameObject); //Remove the object from the scene
- }
- }
- function OnTriggerEnter (other : Collider) //Check for collisions with gameobjects tagged "Astroid"
- {
- //Check for the asteroid
- if(other.gameObject.tag == "Astroid")
- {
- //Reset the position of the enemy
- other.transform.position.y = 8;
- other.transform.position.x = Random.Range(-7.0,7.0);
- //Create the explosion on impact
- if(explosion)
- {
- Instantiate(explosion, transform.position, transform.rotation); // Create prefab on collision
- audio.PlayClipAtPoint(missileExplodeSound, transform.position);
- }
- //Tell scene manager that we destroyed an enemy and add a point to the score
- sceneManager.transform.GetComponent("ScriptSceneManager").AddScore();
- //Get rid of the bullet
- Destroy(gameObject); //Remove the object from the scene
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement