示例#1
0
    void OnTriggerEnter(Collider collision)
    {
        if (collision.CompareTag("Skier"))                                      // Will be called if collision with a skier occurs.
        {
            Vector3 explosionPos = transform.position;                          // explosion will occur at the impact site.
            explosionPos.y = 0;                                                 //Make sure that there is no y component
            Collider[] colliders = Physics.OverlapSphere(explosionPos, radius); // List of colliders within the radius.
            // animation for the door
            TetheredMineAnimation.SetBool("IsDoorClosed", true);
            TetheredMineAnimation.SetBool("IsDoorOpen", false);
            // Hatch Close Door sound
            AudioManager.Play("TetherObs&BBHatchDoorClosed");
            AudioManager.Play("TetheredMineExplosion");
            foreach (Collider hit in colliders)                                        //For all the objects in the radius,
            {
                if (hit.CompareTag("Skier"))                                           //If this object is a skier,
                {
                    SkierController controller = hit.GetComponent <SkierController>(); // Gets all controllers within the radius.
                    if (!controller.IsInvincible())
                    {
                        controller.HurtSkier(); // Hurts the skier within the radius.
                    }
                }
            }

            ControllerVibrate.VibrateAll(1.0f, 0.5f);                 //Vibrate all controllers very moderately
            gameObject.SetActive(false);                              // Deactivates the mine.
            m_rb.velocity           = Vector3.zero;                   // Resets velocity.
            m_rb.angularVelocity    = Vector3.zero;                   // Resets angular velocity.
            m_rb.transform.rotation = Quaternion.Euler(Vector3.zero); // Resets rotation.
            m_tmAbility.setIsUsingAbility(false);
            m_tmAbility.mineAbilityCooldown.SetTimer();

            explosionPrefab.transform.position = explosionPos;                                                            //Make the explosion happen at the right spot
            Instantiate(explosionPrefab);                                                                                 //Create the explosion

            GameFreezer.Freeze(freezeAmount, freezeFrames);                                                               //Slow time very briefly for impact
        }
        else if (collision.CompareTag("Rock"))                                                                            //If colliding with an obstacle,
        {
            float pushDirection = transform.position.x - collision.transform.position.x;                                  //Calculate if the mine should be pushed left or right
            if (pushDirection > 0)                                                                                        //If positive,
            {
                m_tether.ForceOverTime(new Vector3(m_tmAbility.obstacleForce, 0, 0), m_tmAbility.obstacleForceDuration);  //Push right
            }
            else                                                                                                          //If negative,
            {
                m_tether.ForceOverTime(new Vector3(-m_tmAbility.obstacleForce, 0, 0), m_tmAbility.obstacleForceDuration); //Push left
            }
        }
    }
    void OnCollisionEnter(Collision collision)
    {
        if (collision.gameObject.CompareTag("River"))                                       // Will be called if collision with the river occurs.
        {
            Vector3 explosionPos = transform.position;                                      // explosion will occur at the impact site.
            explosionPos.y = 0;                                                             //Make sure that there is no y component
            Collider[] colliders = Physics.OverlapSphere(explosionPos, m_bbAbility.radius); // List of colliders within the radius.
            AudioManager.Play("BeachBomb POP");

            foreach (Collider hit in colliders)                                                                     //For all the objects in the radius,
            {
                if (hit.CompareTag("Skier"))                                                                        //If this object is a skier,
                {
                    Tether  tether        = hit.GetComponent <Tether>();                                            //Get their tether
                    Vector3 distanceToHit = hit.transform.position - explosionPos;                                  //Get the difference in position between the skier and the explosion point
                    distanceToHit.y = 0;                                                                            //Make sure there is no y compenent
                    Vector3 extraForwardsForce = new Vector3(0, 0, m_bbAbility.extraForwardsPower);                 //Make an extra force up the river to account for always moving forwards
                    Vector3 totalForce         = m_bbAbility.power * distanceToHit.normalized + extraForwardsForce; //Total up the forces
                    tether.ForceOverTime(totalForce, m_bbAbility.forceDuration);                                    //Add a force on the skier, pushing away from the explosion point
                }
                else if (hit.CompareTag("Mine"))
                {
                    Tether  tether        = hit.GetComponent <Tether>();                                                //Get their tether
                    Vector3 distanceToHit = hit.transform.position - explosionPos;                                      //Get the difference in position between the skier and the explosion point
                    distanceToHit.y = 0;                                                                                //Make sure there is no y compenent
                    Vector3 extraForwardsForce = new Vector3(0, 0, m_bbAbility.extraForwardsPower);                     //Make an extra force up the river to account for always moving forwards
                    Vector3 totalForce         = m_bbAbility.minePower * distanceToHit.normalized + extraForwardsForce; //Total up the forces
                    tether.ForceOverTime(totalForce, m_bbAbility.forceDuration);                                        //Add a force on the mine, pushing away from the explosion point
                }
            }

            gameObject.SetActive(false);                              // Deactivates the beachball.
            m_rb.velocity           = Vector3.zero;                   // Resets velocity.
            m_rb.angularVelocity    = Vector3.zero;                   // Resets angular velocity.
            m_rb.transform.rotation = Quaternion.Euler(Vector3.zero); // Resets rotation.

            m_bbAbility.ToggleIsShooting(false);                      // Player isn't shooting anymore.
            m_bbAbility.ToggleMeshEnable(false);                      // Disabled target's mesh.

            explosionPrefab.transform.position = explosionPos;        //Make the explosion happen at the right spot
            Instantiate(explosionPrefab);                             //Create the explosion

            ControllerVibrate.VibrateAll(0.2f, 0.5f);                 //Vibrate all controllers a meduim amount

            GameFreezer.Freeze(freezeAmount, freezeFrames);           //Slow time very briefly for impact
        }
    }
示例#3
0
    //Hurts the skier and checks their lives
    public void HurtSkier()
    {
        if (!m_invincible)             //Double checking that they aren't invincible,
        {
            lives--;                   //Hurt the skier
            hurtThisFrame = true;      //Set hurt to true
            StartCoroutine(HurtOff()); //Set hurt to false at the end of the frame
            //sets DamageTaken trigger in animator
            characterAnim.SetTrigger("DamageTaken");
            ControllerVibrate.VibrateController((int)controller - 1, 0.025f, 0.15f); //Give the controller a small vibration
            foreach (ParticleSystem p in m_obstacleParticles)                        //Play the damage particle effects
            {
                p.Play();
            }
        }

        if (lives <= 0)                                                 //If the skier is out of lives,
        {
            characterAnim.SetBool("IsDead", true);
            m_isAlive            = false;           //He dead
            tether.enabled       = false;           //Turn movement off
            m_scoreTimer.enabled = false;           //Stop the score from increasing
            AudioManager.Play("Wipeout");           // plays the wipeout sound effect
        }
        else                                        //If the skier is still alive,
        {
            m_invincible      = true;               //Make it invincible
            m_skierMultiplier = 1;                  // Multiplier is reset back to 1.
            m_scoreMultiplierTimer.enabled = false; // Resets the timer before the flashes start so they don't have the multiplier increase during thier invincibility.

            //Flash the skier mesh
            for (int i = 0; i < numberOfFlashes; ++i)                                       //Repeating for the number of flashes,
            {
                StartCoroutine(MeshOff(flashDelay * i * 2));                                //Schedule the mesh to turn off, every even interval
                StartCoroutine(MeshOn(flashDelay * i * 2 + flashDelay));                    //Schedule the mesh to turn on, every odd interval
            }
            StartCoroutine(InvincibleOff(flashDelay * numberOfFlashes * 2));                //Schedule invincibility to turn off after the flashes are complete
        }
    }
    public static ControllerVibrate instance;     //Store a static instance of itself

    private void Awake()
    {
        instance = this;            //Set the instance to itself
    }