Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // PLAYER SCRIPT -This script handles most of the gameplay along with ScriptSceneManager
- var playerSpeedVertical = 8.0;
- var playerSpeedHorizontal = 8.0;
- var horMin = -6.0;
- var horMax = 6.0;
- var verMin = -8.0;
- var verMax = 8.0;
- var laser : Transform;
- var laserCanonM : Transform;
- var laserSound : AudioClip;
- var redLaser : Transform;
- var laserCanonL : Transform;
- var laserCanonR : Transform;
- var redLaserSound : AudioClip;
- var playerOriginY = -5.882426;
- var playerOriginX = 0;
- var coolDownTime = 3;
- var missleTurret : Transform;
- var missle : Transform;
- var missleCount = 10;
- var mCountA =50;
- var mCountB =25;
- var mCountC =100;
- var mCountD =35;
- var missleSound : AudioClip;
- var shieldMesh : Transform;
- var shieldKeyInput : KeyCode;
- var shieldActivationSound : AudioClip;
- var numberOfShields = 1;
- var sCountA =50;
- var sCountB =10;
- var sCountC =100;
- var sCountD =20;
- var shieldOn = false;
- var invincible = false;
- var instructions =false;
- var instructionTime =5;
- var w = 300; // used for the MISSLE MODE ENGAGED GUI label
- var h = 300;
- function Update ()
- {
- var transV : float = Input.GetAxis ("Vertical") *playerSpeedVertical *Time.deltaTime;//Stores variable for vertical movement
- var transH : float = Input.GetAxis ("Horizontal") *playerSpeedHorizontal *Time.deltaTime;//Stores variable for horizontal movement
- transform.Translate (transH, transV, 0); //Move the player based on transV + transH variables above
- transform.position.x = Mathf.Clamp(transform.position.x, horMin, horMax); //Clamp player movement to horizontal limits
- transform.position.y = Mathf.Clamp(transform.position.y, verMin, verMax); //Clamp player movement to vertical limits
- if(Input.GetKeyDown("space")) //check to see if spacebar key is pushed, if it is run code inside the if brackets
- {
- if(ScriptSceneManager.doubleShotMode == true) //Check to see if doubleShotMode is activated
- { // if it's activated fire a doubleLaser blast when user presses the space key
- Instantiate (redLaser, laserCanonL.position, laserCanonL.rotation);//create a redLaser prefab at laserCanonL pos.&rot.
- Instantiate (redLaser, laserCanonR.position, laserCanonR.rotation); //create a redLaser prefab at laserCanonR pos.&rot.
- audio.PlayClipAtPoint(redLaserSound, transform.position); //play redLaserSound audio
- }
- else
- {
- Instantiate (laser, laserCanonM.position, laserCanonM.rotation); //create a laser prefab at laserCanon(middle) pos.&rot.
- audio.PlayClipAtPoint(laserSound, transform.position); // play laser blast sound
- }
- }
- if(Input.GetKeyDown("m")&&ScriptSceneManager.missleMode==true)//fire a pair of missles when user presses the m key if in misslemode
- {
- if(missleCount >=1)
- {
- Instantiate (missle, missleTurret.position,missleTurret.rotation); //create the missle prefab
- audio.PlayClipAtPoint(missleSound, transform.position); // play missle launch sound
- missleCount -=1;
- }
- }
- if(Input.GetKeyDown(shieldKeyInput)) // If user pushes inspector chosen keyboard key
- {
- if(!shieldOn) //if the Shield is not on run the code inside
- {
- var clone = Instantiate (shieldMesh, transform.position, transform.rotation); //create the shield prefab
- clone.transform.parent = gameObject.transform; // place the shield mesh at the same point(transform) as the game object(player)
- audio.PlayClipAtPoint(shieldActivationSound, transform.position); //play shield activation sound
- shieldOn = true;
- numberOfShields -=1;
- }
- }
- }
- function ResetPlayer () //moves the player back to the inspector set origin + play a blinking animation for feedback
- {
- invincible = true; // Make the player invincible
- transform.position.y = playerOriginY; //Reset the position of the player to Y origin
- transform.position.x = playerOriginX; //Reset the position of the player to X origin
- ScriptSceneManager.missleMode =false;
- ScriptSceneManager.doubleShotMode =false;
- animation.Play("Blink", PlayMode.StopAll); // Play the blink animation clip+ stop all other animations
- yield WaitForSeconds(coolDownTime); // wait for inspector set seconds
- animation.Stop("Blink"); // Stop playing the blink animation clip
- invincible = false; // Set the player to not be invincible
- }
- function OnGUI () //Create and Display the HUD information for number of shields and missles left
- { GUI.Label (Rect (sCountA,sCountB,sCountC,sCountD), "Shields left: " +numberOfShields);
- if (ScriptSceneManager.missleMode == true)
- {
- GUI.Label (Rect (mCountA,mCountB,mCountC,mCountD), "Missles left: " +missleCount);
- if(instructions == true)
- {
- ShowInstructions();
- }
- }
- }
- function ShowInstructions()
- {
- var rect = Rect((Screen.width-w)/2, (Screen.height-h)/2, w, h);
- if(instructions == true)
- {
- GUI.Label (rect, "MISSLE MODE ENGAGED! Press M to fire missles. You only have 10, so use them wisely!");
- }
- yield WaitForSeconds(instructionTime);
- instructions = false;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement