Example #1
0
 public void ShakeDieStarve()
 {
     myShake = CameraShaker.Instance.StartShake(1f, 1f, 2f);
 }
Example #2
0
 private void OnDestroy()
 {
     _shakeShieldInstance = null;
     _shakePlayerInstance = null;
     CS = null;
 }
Example #3
0
    void OnGUI()
    {
        if (Input.GetKeyDown(KeyCode.R))
        {
            SceneManager.LoadScene(SceneManager.GetActiveScene().name);
            //Application.LoadLevel(Application.loadedLevel);
        }

        Slider s = delegate(float val, string prefix, float min, float max, int pad)
        {
            GUILayout.BeginHorizontal();
            GUILayout.Label(prefix, GUILayout.MaxWidth(pad));
            val = GUILayout.HorizontalSlider(val, min, max);
            GUILayout.Label(val.ToString("F2"), GUILayout.MaxWidth(50));
            GUILayout.EndHorizontal();
            return(val);
        };

        GUI.Box(new Rect(10, 10, 250, Screen.height - 15), "Make-A-Shake");
        GUILayout.BeginArea(new Rect(29f, 40, 215, Screen.height - 40));

        GUILayout.Label("--Position Infleunce--");
        posInf.x = s(posInf.x, "X", 0, 4, 25);
        posInf.y = s(posInf.y, "Y", 0, 4, 25);
        posInf.z = s(posInf.z, "Z", 0, 4, 25);

        GUILayout.Label("--Rotation Infleunce--");
        rotInf.x = s(rotInf.x, "X", 0, 4, 25);
        rotInf.y = s(rotInf.y, "Y", 0, 4, 25);
        rotInf.z = s(rotInf.z, "Z", 0, 4, 25);

        GUILayout.Label("--Other Properties--");

        magn  = s(magn, "Magnitude:", 0, 10, 75);
        rough = s(rough, "Roughness:", 0, 20, 75);

        fadeIn  = s(fadeIn, "Fade In:", 0, 10, 75);
        fadeOut = s(fadeOut, "Fade Out:", 0, 10, 75);

        GUILayout.Label("--Saved Shake Instance--");
        GUILayout.Label("You can save shake instances and modify their properties at runtime.");

        if (shake == null && GUILayout.Button("Create Shake Instance"))
        {
            shake = CameraShaker.Instance.StartShake(magn, rough, fadeIn);
            shake.DeleteOnInactive = false;
        }

        if (shake != null)
        {
            if (GUILayout.Button("Delete Shake Instance"))
            {
                shake.DeleteOnInactive = true;
                shake.StartFadeOut(fadeOut);
                shake = null;
            }

            if (shake != null)
            {
                GUILayout.BeginHorizontal();
                if (GUILayout.Button("Fade Out"))
                {
                    shake.StartFadeOut(fadeOut);
                }
                if (GUILayout.Button("Fade In"))
                {
                    shake.StartFadeIn(fadeIn);
                }
                GUILayout.EndHorizontal();

                modValues = GUILayout.Toggle(modValues, "Modify Instance Values");

                if (modValues)
                {
                    shake.ScaleMagnitude    = magn;
                    shake.ScaleRoughness    = rough;
                    shake.PositionInfluence = posInf;
                    shake.RotationInfluence = rotInf;
                }
            }
        }

        GUILayout.Label("--Shake Once--");
        GUILayout.Label("You can simply have a shake that automatically starts and stops too.");

        if (GUILayout.Button("Shake!"))
        {
            CameraShakeInstance c = CameraShaker.Instance.ShakeOnce(magn, rough, fadeIn, fadeOut);
            c.PositionInfluence = posInf;
            c.RotationInfluence = rotInf;
        }

        GUILayout.EndArea();

        float height;

        if (!showList)
        {
            height = 120;
        }
        else
        {
            height = 120 + CameraShaker.Instance.ShakeInstances.Count * 130f;
        }

        GUI.Box(new Rect(Screen.width - 310, 10, 300, height), "Shake Instance List");
        GUILayout.BeginArea(new Rect(Screen.width - 285, 40, 255, Screen.height - 40));

        GUILayout.Label("All shake instances are saved and stacked as long as they are active.");

        showList = GUILayout.Toggle(showList, "Show List");

        if (showList)
        {
            int index = 1;
            foreach (CameraShakeInstance c in CameraShaker.Instance.ShakeInstances)
            {
                string state = c.CurrentState.ToString();

                GUILayout.Label("#" + index + ": Magnitude: " + c.Magnitude.ToString("F2") + ", Roughness: " + c.Roughness.ToString("F2"));
                GUILayout.Label("      Position Influence: " + c.PositionInfluence);
                GUILayout.Label("      Rotation Influence: " + c.RotationInfluence);
                GUILayout.Label("      State: " + state);
                GUILayout.Label("- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -");
                index++;
            }
        }
        GUILayout.EndArea();
    }
 void Start()
 {
     //Create the shake instance. We will modify its properties in Update()
     _shakeInstance = CameraShakerManager.GetCameraShaker("Main Camera").StartShake(2, 14, 0);
 }
Example #5
0
 void Start()
 {
     //Create the shake instance. We will modify its properties in Update()
     _shakeInstance = CameraShaker.Instance.StartShake(2, 14, 0);
 }
    public static void ShakeCamera(CameraShakeCreator cameraShakeParameters)
    {
        CameraShakeInstance cameraShakeInstance = cameraShakeParameters.GetInstance();

        CameraShaker.Instance.Shake(cameraShakeInstance);
    }
Example #7
0
    void OnTriggerEnter(Collider other)                      //The cannonball hit something
    {
        if (other.tag == "Player")                           //The cannonball hit the player
        {
            if (CheatCodesScript.godMode == false)           //The player has not activated Godmode
            {
                source.clip = hitSounds[Random.Range(0, 3)]; //Play a random audioclip
                source.Play();

                GameControl.control.health -= damageOutput;                                 //Damage the player
                other.GetComponentInChildren <ChangeMaterial> ().checkPlayerHealth();       //See if the player should change material
                if (GameControl.control.health <= 0)                                        //If true, the player is dead
                {
                    other.GetComponentInParent <DeadPlayer>().enabled = true;               //Activate the DeadPlayer script
                    other.GetComponentInParent <DeadPlayer>().killPlayer();                 //Kill the player via DeadPlayer.cs
                }
                CameraShakeInstance c = CameraShaker.Instance.ShakeOnce(1, 5, 0.10f, 0.8f); //This actually instantiates the camera shake. Do NOT remove this line of code.

                Instantiate(explosion, this.transform.position, this.transform.rotation);   //Instantiate the explosion simulation at this cannonballs position.
                this.GetComponent <MeshFilter>().mesh = null;                               //Remove the mesh of this object to make it invisible
                Destroy(this.gameObject, source.clip.length);                               //Destroy this object when the audioclip is done playing
            }
        }

        if (other.tag == "aiShip")                                                                                                                                                    //The projectile hit an enemy
        {
            if (other.transform.root.name == "Cargo(Clone)")                                                                                                                          //It his a cargo ship
            {
                other.transform.GetComponentInParent <AIMaster>().thisAIFlee();                                                                                                       //Make the cargo ship flee
            }
            if (other.transform.root.name == "Boss(Clone)")                                                                                                                           //It hit the boss
            {
                if ((other.GetComponentInParent <AIMaster> ().aiHealth - damageOutput) <= 0)                                                                                          //The next cannonball is going to kill the boss
                {
                    other.GetComponentInParent <BossTalking> ().enabled = true;                                                                                                       //Start the last dialogue
                    other.GetComponentInParent <BossTalking> ().findAllDialogElements();                                                                                              //Opens all GUI elements needed for the dialogue
                    other.GetComponentInParent <BossTalking> ().dialogBoss(12);                                                                                                       //Display correct player animation
                    other.GetComponentInParent <BossTalking> ().nextButton.GetComponent <Button> ().onClick.AddListener(delegate { GameControl.control.ChangeScene("cog_screen"); }); //The next time the "next button" is pressed, load the cog_screen scene
                }
            }

            if (other.GetComponentInParent <AIMaster>().isDead == false)                                          //We make sure the projectile don't hit an already dead ship.
            {
                if (SceneManager.GetActiveScene().name != "Tutorial")                                             //Make sure this is not the tutorial scene
                {
                    if (other.GetComponentInParent <AIMaster>().isBoss == true && GameControl.control.health > 0) //Boss can only loose health if player is alive
                    {
                        other.GetComponentInParent <AIMaster>().aiHealth -= damageOutput;                         //Deal damage to the hit ai
                    }
                    else if (other.GetComponentInParent <AIMaster>().isBoss == false)                             //If it did not hit the boss, damage none the less
                    {
                        other.GetComponentInParent <AIMaster>().aiHealth -= damageOutput;                         //Deal damage to the hit ai
                    }
                }
                else                                                                                                                 //This is in the tutorial scene
                {
                    other.GetComponentInParent <AIMaster>().aiHealth -= damageOutput;                                                //Deal damage to the marine
                }
                if (other.transform.GetComponentInParent <AIMaster> ().aiHealth <= 0)                                                //If the marine has less than 0 health, kill it
                {
                    other.transform.GetComponentInParent <AIMaster> ().killAI();                                                     //Kills the marine
                }
                else if (other.GetComponentInParent <AIMaster> ().aiHealth <= other.GetComponentInParent <AIMaster> ().aiHealthMat3) //It should not die, but should change material
                {
                    if (other.GetComponentInParent <AIMaster> ().usingMat3 != true)                                                  //Has not changed to mat3 yet
                    {
                        characterWindows.setHappy("Player");                                                                         //The player is happy the marine got damaged
                    }
                    other.GetComponentInParent <AIMaster> ().changeMat3();                                                           //Change the material
                }
                else if (other.GetComponentInParent <AIMaster> ().aiHealth <= other.GetComponentInParent <AIMaster> ().aiHealthMat2) //It should not die, but should change material
                {
                    if (other.GetComponentInParent <AIMaster> ().usingMat2 != true)                                                  //Has not changed to mat2 yet
                    {
                        characterWindows.setHappy("Player");                                                                         //The player is happy the marine got damaged
                    }
                    other.GetComponentInParent <AIMaster> ().changeMat2();                                                           //Change the material
                }

                if (other.transform.root.name == "Marine(Clone)" && other.GetComponentInParent <AIMaster>().aiHealth > 0) //Hit a marine, and the health of the marine is greater than 0
                {
                    if (SceneManager.GetActiveScene().name != "Tutorial")                                                 //We are not in the tutorial scene
                    {
                        if (GameControl.control.isFighting == false)                                                      //A fight is not ongoing, so we engage this marine in a fight with the player
                        {
                            other.transform.GetComponentInParent <AIMaster>().deaktivatePatroling();                      //Start the fight
                        }
                    }
                }

                characterWindows.setAngry("Enemy");                                           //Make the enemy angry because it got hit
                Instantiate(explosion, this.transform.position, this.transform.rotation);     //Instantiate a particle simulation where the cannonball is at this time
                this.GetComponent <MeshFilter>().mesh = null;                                 //Remove the mesh of the cannonball, making it invisible
                source.clip = hitSounds[Random.Range(0, 3)];                                  //Play a random audioclip
                source.Play();
                Destroy(this.gameObject, source.clip.length);                                 //Delete this cannonball when the audio is done playing
            }
            else                                                                              //Hit an enemy that is dead
            {
                if (other.GetComponentInParent <AIMaster>().source.isPlaying == false)        //The clip played when an enemy dies is no longer playing
                {
                    Instantiate(explosion, this.transform.position, this.transform.rotation); //Instantiate a particle simulation at this position
                    this.GetComponent <MeshFilter>().mesh = null;                             //Remove the mesh of the cannonball, making it invisible
                    source.clip = hitSounds[Random.Range(0, 3)];                              //Play a random audioclip
                    source.Play();
                    Destroy(this.gameObject, source.clip.length);                             //Delete this cannonball when the audio is done playing
                }
                else                                                                          //The audioclip is still playing, so we don't want to have multiple tiny clips from the cannonballs too
                {
                    Instantiate(explosion, this.transform.position, this.transform.rotation); //Instantiate a particle simulation at this position
                    Destroy(this.gameObject);                                                 //Delete this object
                }
            }
        }

        if (other.tag == "shop" || other.tag == "Planet" || other.tag == "asteroid" || other.tag == "Moon") //The cannonball hit a hindering, not an enemy or player
        {
            source.clip = hitSounds[Random.Range(0, 3)];                                                    //Play a random audioclip
            if (this.gameObject != null)                                                                    //The cannonball is not deleted yet
            {
                source.Play();                                                                              //Play the clip
            }
            Instantiate(explosion, this.transform.position, this.transform.rotation);                       //Instantiate a particle simulation where the cannonball is at this time
            this.GetComponent <MeshFilter>().mesh = null;                                                   //Remove the mesh of the cannonball, making it invisible
            Destroy(this.gameObject, source.clip.length);                                                   //Delete this cannonball when the audio is done playing
        }
    }
Example #8
0
 /// <summary>
 /// Starts a shake using the given preset.
 /// </summary>
 /// <param name="shake">The preset to use.</param>
 /// <returns>A CameraShakeInstance that can be used to alter the shake's properties.</returns>
 public CameraShakeInstance Shake(CameraShakeInstance shake)
 {
     cameraShakeInstances.Add(shake);
     return(shake);
 }
Example #9
0
 void shakeEnemy()
 {
     shaker = CameraShaker.Instance.StartShake(Magnitude, Roughness, FadeInTime);
 }
Example #10
0
    // Update is called once per frame
    void FixedUpdate()
    {
        // removing and adding the boosting bar
        // if the player is in combat, and the boost bar is not active, set it active
        if (GameControl.control.isFighting && !boostBar.activeSelf)
        {
            boostBar.SetActive(true);
        }

        // if the player is not in combat, and the boostbar is both active and full, set it inactive
        else if (!GameControl.control.isFighting && boostBar.activeSelf && boostCooledDown)
        {
            boostBar.SetActive(false);
        }

        // Setting the value of the boost resource to 0 if it is equal or less than 0
        if (boostCooldownTimer <= 0f)
        {
            boostCooldownTimer = 0f;
            isBoosting         = false;     // we are no longer boosting either if the resource is empty
        }
        else if (boostCooldownTimer < 3f)   // Setting false that the boost is completely cooled down if it is less than 3
        {
            boostCooledDown = false;
        }

        // if the boosting resource is not full, and the player is either not boosting while in combat, OR is not in combat
        if ((boostCooldownTimer < 3f && isBoosting == false && GameControl.control.isFighting == true) ||
            (boostCooldownTimer < 3f && GameControl.control.isFighting == false))
        {
            // if the timer that starts the replenishing of the boosting resource is between -0.1 and 3.1, not pressing down left shift
            // and in combat, then the timer for replenishing the boosting resource should start counting down
            if (waitForBoost > -0.1f && waitForBoost < 3.1f && !Input.GetKey(KeyCode.LeftShift) && GameControl.control.isFighting)
            {
                waitForBoost -= Time.deltaTime;
            }
            // if the player is not in combat, and the timer for waiting for the boost to replenish is above 0, it is set to 0 to start
            // filling up the boost meter immediately
            if (!GameControl.control.isFighting && waitForBoost > 0)
            {
                waitForBoost = 0;
            }

            // if the timer for the boost has reached or is below 0, it should start replenishing the boosting resource
            if (waitForBoost <= 0)
            {
                boostCooldownTimer += Time.deltaTime / 3;     // replenishing the boosting resource at the time it takes to complete a frame divided by 3
                if (boostCooldownTimer >= 3f)                 // if the boost cooldown timer has reached its max number or above
                {
                    boostCooledDown    = true;                // the boost is set to have been cooled down
                    boostCooldownTimer = 3f;                  // the boosting resource is 3
                }
            }
        }

        if (hitBomb == true)
        {
            bombTimer += Time.deltaTime;
            if (bombTimer >= 1)
            {
                bombTimer = 0;
                hitBomb   = false;
                this.transform.root.GetComponent <Rigidbody>().mass        = 1;
                this.transform.root.GetComponent <Rigidbody>().drag        = 0.5f;
                this.transform.root.GetComponent <Rigidbody>().angularDrag = 0.5f;
            }
        }

        if (hitBomb == false && GameControl.control.health > 0) // if the player has not been hit, and is alive
        {
            if (Input.GetKey(KeyCode.LeftShift))                // the key that enables the player to boost
            {
                // if we are in combat and we have resources to boost with
                if (GameControl.control.isFighting && boostCooldownTimer > 0)
                {
                    Boost();                     // calling the boosting function
                }

                // if we are not in combat
                else if (!GameControl.control.isFighting)
                {
                    Boost();                     // calling the boost function
                }
            }

            else             // if not left shift is down, the player is not boosting
            {
                isBoosting = false;
            }

            // checking only if the player has pressed down the button, not if is actively down
            if (Input.GetKeyDown(KeyCode.LeftShift))
            {
                if (!GameControl.control.isFighting)                 // if the player is not in combat
                {
                    // the camera shakes as you press the boost button
                    CameraShakeInstance c = CameraShaker.Instance.ShakeOnce(1, 5, 0.10f, 0.8f);
                }
                // if the player is in combat, and the boost resource is above 0, ie. can boost
                else if (GameControl.control.isFighting && boostCooldownTimer > 0f)
                {
                    // the camera shakes as you press the boost button
                    CameraShakeInstance c = CameraShaker.Instance.ShakeOnce(1, 5, 0.10f, 0.8f);
                }
            }

            // if the player is pressing the forwards key, and is not boosting
            if (Input.GetKey(KeyCode.W) && isBoosting == false)
            {
                if (TutorialControl != null && TutorialControl.GetComponent <Tutorial> ().wadCheck [0] == false)
                {
                    TutorialControl.GetComponent <Tutorial> ().wadCheck [0] = true;
                    TutorialControl.GetComponent <Tutorial> ().checkArray(TutorialControl.GetComponent <Tutorial> ().wadCheck);
                }

                goingForward = true;                                         // the player is moving forward
                player.AddForce(transform.forward * force * Time.deltaTime); //adding force to the player so that they accelerate

                // Series of if tests seeing if the player can accelerate in the diffrent directions in the x- and z-axis
                if (player.velocity.x >= maxVelocity.x)
                {
                    player.velocity = new Vector3(maxVelocity.x, 0.0f, player.velocity.z);
                }

                if (player.velocity.x <= -maxVelocity.x)
                {
                    player.velocity = new Vector3(-maxVelocity.x, 0.0f, player.velocity.z);
                }

                if (player.velocity.z >= maxVelocity.z)
                {
                    player.velocity = new Vector3(player.velocity.x, 0.0f, maxVelocity.z);
                }

                if (player.velocity.z <= -maxVelocity.z)
                {
                    player.velocity = new Vector3(player.velocity.x, 0.0f, -maxVelocity.z);
                }
            }
            else             // if this is not true, the player is not moving forward
            {
                goingForward = false;
            }

            if (Input.GetKey(KeyCode.A))      // if the player is turning to the left
            {
                if (TutorialControl != null && TutorialControl.GetComponent <Tutorial> ().wadCheck [1] != true)
                {
                    TutorialControl.GetComponent <Tutorial> ().wadCheck [1] = true;
                    TutorialControl.GetComponent <Tutorial> ().checkArray(TutorialControl.GetComponent <Tutorial> ().wadCheck);
                }
                // we rotate the player to the left using the turn speed * the frames in game in real time
                transform.Rotate(Vector3.down, turnSpeed * Time.deltaTime);
                turnLeft = true;                 // the player is turning left
            }

            else     // if the button press is not true, the player is not turning left
            {
                turnLeft = false;
            }

            if (Input.GetKey(KeyCode.D))              // if the player is turning right
            {
                if (TutorialControl != null && TutorialControl.GetComponent <Tutorial> ().wadCheck [2] != true)
                {
                    TutorialControl.GetComponent <Tutorial> ().wadCheck [2] = true;
                    TutorialControl.GetComponent <Tutorial> ().checkArray(TutorialControl.GetComponent <Tutorial> ().wadCheck);
                }
                // we rotate the player to the right using the turn speed * the frames in game in real time
                transform.Rotate(Vector3.up, turnSpeed * Time.deltaTime);
                turnRight = true;                 // the player is turning right
            }

            else     // if the button press is not true, then we are not turning right
            {
                turnRight = false;
            }
        }
    }
 private void Start()
 {
     _shakeInstance = CameraShaker.Instance.StartShake(2f, 15f, 2f);
     _shakeInstance.StartFadeOut(0f);
     _shakeInstance.DeleteOnInactive = true;
 }
Example #12
0
 // Starts a shake using the given preset
 public CameraShakeInstance Shake(CameraShakeInstance shake)
 {
     // Add preset to the list of camera shake instaces
     cameraShakeInstances.Add(shake);
     return(shake);
 }