Ejemplo n.º 1
0
 void Update()
 {
     if (_afpcPlayer != null && colliding)
     {
         timeSinceLastCall += Time.deltaTime;
         _healthMngr        = _afpcPlayer.GetComponent <AFPC_HealthManager> ();
         if (timeSinceLastCall > healthDecreaseDelay)
         {
             _healthMngr.DecreaseHealth(healthToDecrease);
             timeSinceLastCall = 0f;
         }
     }
 }
Ejemplo n.º 2
0
 void OnTriggerStay(Collider coll)
 {
     if (coll.gameObject.GetComponent <AFPC_PlayerMovement> () && text != null)
     {
         _afpcPlayer = coll.gameObject.GetComponent <AFPC_PlayerMovement> ();
         _spawnMngr  = _afpcPlayer.GetComponent <AFPC_SpawnManager> ();
         if (_afpcPlayer.playerType == AFPC_PlayerMovement.PlayerType.rigidBodyPlayer && !_spawnMngr.HasDied)
         {
             text.gameObject.SetActive(true);
             text.text = desiredText;
         }
         else if (_afpcPlayer.playerType == AFPC_PlayerMovement.PlayerType.rigidBodyPlayer && _spawnMngr.HasDied)
         {
             text.gameObject.SetActive(false);
         }
     }
 }
Ejemplo n.º 3
0
 // Use this for initialization
 void Start()
 {
     cameraOriginalRotation = transform.rotation;
     cameraStartPos         = transform.localPosition;
     ClimbBobCurveTime      = climbBobCurve [climbBobCurve.length - 1].time;
     if (afpcPlayer == null)
     {
         afpcPlayer = GameObject.FindObjectOfType <AFPC_PlayerMovement> ();
     }
     if (afpcPlayer != null)
     {
         spawnManager = afpcPlayer.gameObject.GetComponent <AFPC_SpawnManager> ();
         _audioSrc    = afpcPlayer.GetComponent <AudioSource> ();
     }
     if (jumpkickBack == null)
     {
         jumpkickBack = transform.parent.gameObject;
     }
     jumpKickBackAnimationController = jumpkickBack.GetComponent <Animator> ();
     jumpKickBackTriggerHashId       = Animator.StringToHash("DoJumpKickBack");
 }
Ejemplo n.º 4
0
    // Update is called once per frame
    void Update()
    {
        if (previousUseUnderwaterImageEffects != _cam.useUnderwaterImageEffects)
        {
            SwitchImageEffects();
        }
        previousUseUnderwaterImageEffects = _cam.useUnderwaterImageEffects;
        if (!isUnderWater)
        {
            playingUnderWaterSound = false;
        }

        if (_audioSrc.clip == playerUnderWaterSoundEffect)
        {
            _audioSrc.loop = true;
        }
        else
        {
            _audioSrc.loop = false;
        }

        if (afpcPlayer != null)
        {
            if (afpcPlayer.playerState != AFPC_PlayerMovement.PlayerStates.Swim_2)
            {
                // Make sure to stop making ripples and water splashes when we switch back to our previous State
                CancelInvoke("InstantiateWaterStaticRipple");
                invokeStaticRippleFlag = false;
                CancelInvoke("InstantiateWaterMovementSplash");
                invokeMovementSplashFlag = false;
            }
        }

        if (afpcPlayer != null && playerInWaterZone && afpcPlayer.playerType == AFPC_PlayerMovement.PlayerType.rigidBodyPlayer && !afpcPlayer.downHold)
        {
            if (!isUnderWater)
            {
                playerRigidbody = afpcPlayer.GetComponent <Rigidbody> ();
                if (playerRigidbody.velocity.y < float.Epsilon && (playerRigidbody.velocity.x < float.Epsilon || playerRigidbody.velocity.z < float.Epsilon))
                {
                    float dist = 0f;
                    if (waterPlane != null)
                    {
                        dist = waterPlane.transform.position.y - 0.1f;
                    }
                    else
                    {
                        dist = afpcPlayer.transform.position.y;
                    }
                    playerRigidbody.MovePosition(Vector3.SmoothDamp(afpcPlayer.transform.position, new Vector3(afpcPlayer.transform.position.x, dist, afpcPlayer.transform.position.z), ref currV, 0.5f));
                }
            }
        }
        // It ensures that the underwater effect only take place when player eyes or Camera are inside water
        if (playerInWaterZone && playerCamera.transform.position.y < waterPlane.transform.position.y /* It means player is underwater*/)
        {
            if (afpcPlayer.playerType == AFPC_PlayerMovement.PlayerType.rigidBodyPlayer)
            {
                invokePlayerMovementSoundFlag = false;
                CancelInvoke("PlayerMovementSound");
                CancelInvoke("InstantiateWaterStaticRipple");
                invokeStaticRippleFlag = false;
                CancelInvoke("InstantiateWaterMovementSplash");
                invokeMovementSplashFlag = false;
            }
            if (_cam.useUnderwaterImageEffects)
            {
                imageEffectsCamera.GetComponent <AFPC_UnderWaterDisplaceEffect> ().enabled = true;
                imageEffectsCamera.GetComponent <AFPC_UnderWaterBlurEffect> ().enabled     = true;
            }
            if (useWaterSoundEffects && playerUnderWaterSoundEffect != null)
            {
                if (afpcPlayer.playerType == AFPC_PlayerMovement.PlayerType.rigidBodyPlayer && !playingUnderWaterSound)
                {
                    _audioSrc.clip = playerUnderWaterSoundEffect;
                    _audioSrc.Play();
                    playingUnderWaterSound = true;
                }
            }
            isUnderWater = true;
            if (flipPlane)
            {
                if (waterPlane.transform.localRotation.x >= 0f)
                {
                    Quaternion requiredRotation = new Quaternion(-waterPlane.localRotation.x, waterPlane.localRotation.y, waterPlane.localRotation.z, waterPlane.localRotation.w);
                    waterPlane.localRotation = requiredRotation;
                }
            }
            if (afpcPlayer != null)
            {
                if (afpcPlayer.playerType == AFPC_PlayerMovement.PlayerType.rigidBodyPlayer)
                {
                    afpcPlayer.DecreaseOxygen       = true;
                    afpcPlayer.playerOnWaterSurface = false;
                    afpcPlayer.GetComponent <Rigidbody> ().useGravity = afpcPlayer.useGravityWhileSwimming;
                }
            }
            RenderSettings.fog        = true;
            RenderSettings.fogColor   = fogColor;
            RenderSettings.fogMode    = fogMode;
            RenderSettings.fogDensity = fogDensity;
        }
        else if (playerInWaterZone && Mathf.Abs(playerCamera.transform.position.y - waterPlane.transform.position.y) < 0.4f && Mathf.Abs(playerCamera.transform.position.y - waterPlane.transform.position.y) > 0.05f)
        {
            _audioSrc.Stop();
            if (afpcPlayer != null)
            {
                afpcPlayer.playerOnWaterSurface = true;
            }

            if (_cam.useUnderwaterImageEffects)
            {
                imageEffectsCamera.GetComponent <AFPC_UnderWaterDisplaceEffect> ().enabled = false;
                imageEffectsCamera.GetComponent <AFPC_UnderWaterBlurEffect> ().enabled     = false;
            }
            if (flipPlane)
            {
                if (waterPlane.transform.localRotation.x <= 0f)
                {
                    Quaternion requiredRotation = new Quaternion(-waterPlane.localRotation.x, waterPlane.localRotation.y, waterPlane.localRotation.z, waterPlane.localRotation.w);
                    waterPlane.localRotation = requiredRotation;
                }
            }
            if (afpcPlayer != null)
            {
                if (afpcPlayer.playerType == AFPC_PlayerMovement.PlayerType.rigidBodyPlayer)
                {
                    afpcPlayer.DecreaseOxygen        = false;
                    afpcPlayer.CanJumpOnWaterSurface = true;
                    if (afpcPlayer.GetComponent <Rigidbody> ().velocity.sqrMagnitude > 2f)
                    {
                        CancelInvoke("InstantiateWaterStaticRipple");
                        invokeStaticRippleFlag = false;
                        if (!invokeMovementSplashFlag)
                        {
                            invokeMovementSplashFlag = true;
                            InvokeRepeating("InstantiateWaterMovementSplash", 0.01f, 0.2f);
                        }
                        if (useWaterSoundEffects && playerWaterMovementSoundOnWaterSurface != null && !invokePlayerMovementSoundFlag)
                        {
                            invokePlayerMovementSoundFlag = true;
                            InvokeRepeating("PlayerMovementSound", 0.01f, timeToReapeatPlayerMovementSound);
                        }
                    }
                    else if (afpcPlayer.GetComponent <Rigidbody> ().velocity.sqrMagnitude < 2f)
                    {
                        invokeMovementSplashFlag      = false;
                        invokePlayerMovementSoundFlag = false;
                        CancelInvoke("PlayerMovementSound");
                        CancelInvoke("InstantiateWaterMovementSplash");
                        if (!invokeStaticRippleFlag)
                        {
                            invokeStaticRippleFlag = true;
                            InvokeRepeating("InstantiateWaterStaticRipple", 0.01f, 0.25f);
                        }
                    }
                }
            }

            isUnderWater              = false;
            RenderSettings.fog        = initialFogEnabled;
            RenderSettings.fogColor   = initialFogColor;
            RenderSettings.fogMode    = initialFogMode;
            RenderSettings.fogDensity = initialFogDensity;
        }
        else
        {
            if (afpcPlayer != null)
            {
                if (afpcPlayer.playerType == AFPC_PlayerMovement.PlayerType.rigidBodyPlayer)
                {
                    invokePlayerMovementSoundFlag = false;
                    CancelInvoke("PlayerMovementSound");
                    _audioSrc.Stop();
                }
            }
            if (flipPlane)
            {
                if (waterPlane.transform.localRotation.x <= 0f)
                {
                    Quaternion requiredRotation = new Quaternion(-waterPlane.localRotation.x, waterPlane.localRotation.y, waterPlane.localRotation.z, waterPlane.localRotation.w);
                    waterPlane.localRotation = requiredRotation;
                }
            }
            if (_cam.useUnderwaterImageEffects)
            {
                imageEffectsCamera.GetComponent <AFPC_UnderWaterDisplaceEffect> ().enabled = false;
                imageEffectsCamera.GetComponent <AFPC_UnderWaterBlurEffect> ().enabled     = false;
            }
            if (afpcPlayer != null)
            {
                if (afpcPlayer.playerType == AFPC_PlayerMovement.PlayerType.rigidBodyPlayer)
                {
                    afpcPlayer.DecreaseOxygen        = false;
                    afpcPlayer.CanJumpOnWaterSurface = false;
                    afpcPlayer.playerOnWaterSurface  = false;
                }
            }

            isUnderWater              = false;
            RenderSettings.fog        = initialFogEnabled;
            RenderSettings.fogColor   = initialFogColor;
            RenderSettings.fogMode    = initialFogMode;
            RenderSettings.fogDensity = initialFogDensity;
        }
    }