Exemple #1
0
    // Update is called once per frame
    void Update()
    {
        if (!mAttacked)
        {
            moveTarget         = lunchTargets[0].transform.position;
            agent.speed        = defaultSpeed;
            agent.acceleration = defaultAccel;
            if ((Time.time > lungeCooldown + lungeStartTime) && canEverLunge)
            {
                canLunge = true;
            }
        }
        else
        {
            if (Time.time > lungeChargeTime + lungeStartTime)
            {
                agent.speed = lungeSpeed;
                GetComponent <Animator>().Play("Dive");
                agent.acceleration = lungeAccel;
                Ray pathToPoint = new Ray(transform.position, lungeTarget - transform.position);
                lungeTarget = pathToPoint.GetPoint(2f);

                moveTarget = lungeTarget;
            }
            if (Time.time > lungeChargeTime * 2f + lungeStartTime)
            {
                agent.speed = 0f;
                //GetComponent<Animator>().SetFloat("Speed", 0f);
            }
            if (Time.time > lungeChargeTime * 4f + lungeStartTime)
            {
                mAttacked = false;
            }
        }

        if (!mStunCheck.IsStunned)
        {
            agent.Resume();

            GetComponent <Animator>().SetBool("ShockBool", false);
            mStunCheck.UpdateStunInvinciblity();
            //For everything on this level dino can eat
            foreach (GameObject meal in lunchTargets)
            {
                if (meal != null)
                {
                    //Distance from dino to the potential meal
                    float newDistance = Vector3.Distance(this.transform.position, meal.transform.position);
                    //Distance it was travel to last
                    float oldDistance = Vector3.Distance(this.transform.position, moveTarget);
                    //If the potential meal is further from the
                    if (newDistance <= oldDistance)
                    {
                        moveTarget = meal.transform.position;
                        victim     = meal;
                    }
                }
            }

            if (Vector3.Distance(this.transform.position, moveTarget) < chaseDistance)
            {
                if (CanSeePastObstacles())
                {
                    agent.SetDestination(moveTarget);
                    GetComponent <Animator>().SetFloat("Speed", 1f);
                }
            }
            else
            {
                agent.Stop();
                GetComponent <Animator>().SetFloat("Speed", 0f);
            }
            //lunge when the target is close
            if (victim != null && Vector3.Distance(this.transform.position, victim.transform.position) < 3)
            {
                if (!mAttacked && canLunge && canEverLunge)
                {
                    if (mAudioManager)
                    {
                        mAudioManager.PlaySoundEffect("Dino Growl");
                    }
                    mAttacked   = true;
                    canLunge    = false;
                    agent.speed = 0f;
                    //GetComponent<Animator>().SetFloat("Speed", 0f);
                    lungeStartTime = Time.time;
                    //moveTarget = victim.transform.position;
                    //UnityEngine.Debug.Log(moveTarget);
                    lungeTarget = victim.transform.position;
                    Ray pathToPoint = new Ray(transform.position, lungeTarget - transform.position);
                    moveTarget = pathToPoint.GetPoint(1f);
                    //UnityEngine.Debug.Log(moveTarget);
                }
            }

            if (victim != null && Vector3.Distance(this.transform.position, victim.transform.position) < 1)
            {
                GetComponent <Animator>().Play("Eat");
                if (victim.GetComponent <PlayerMovement>() == null)
                {
                    victim.GetComponent <Animator>().Play("Eat");
                }
                if (!eatingThings)
                {
                    if (mAudioManager)
                    {
                        mAudioManager.PlaySoundEffect("Dino Growl");
                        eatingThings = true;
                    }
                }

                if (victim == lunchTargets[0] || (victim.GetComponent <CompanionAI>() != null && victim.GetComponent <CompanionAI>().vitalNPC == true))
                {
                    if (victim.GetComponent <PlayerMovement>() != null && victim.GetComponent <PlayerMovement>().NumberofShields == 0)
                    {
                        victim.GetComponent <Animator>().Play("Eat");
                        if (victim.GetComponent <NavMeshAgent>().enabled == true)
                        {
                            victim.GetComponent <NavMeshAgent>().ResetPath();
                            victim.GetComponent <NavMeshAgent>().enabled = false;
                        }
                        //lunchTargets[0].GetComponent<PlayerMovement>().playDeathAnim();
                        Invoke("restartLevel", mGrowl.length);
                        GameObject.Find("LevelHUDManager").GetComponent <LevelHUD>().playerDied = true;
                        //lunchTargets[0].GetComponent<PlayerMovement>().playDeathAnim();
                    }
                    else if (victim.tag == "Companion" &&
                             ((Vector3.Distance(victim.transform.position, lunchTargets[0].transform.position) <= 2f && lunchTargets[0].GetComponent <PlayerMovement>().NumberofShields == 0) ||
                              (Vector3.Distance(victim.transform.position, lunchTargets[0].transform.position) > 2f)))
                    {
                        victim.GetComponent <CompanionAI>().playDeathAnim();
                        Invoke("restartLevel", mGrowl.length);
                        GameObject.Find("LevelHUDManager").GetComponent <LevelHUD>().vitalNPCDied = true;
                        //lunchTargets[0].GetComponent<CompanionAI>().playDeathAnim();
                        //GetComponent<Keybearer>().posessedKey = victim.GetComponent<Keybearer>().posessedKey;
                        //Destroy(victim);
                        agent.Stop();
                        agent.ResetPath();
                        victim = lunchTargets[0];
                        //moveTarget = victim.transform.position;
                        //mAttacked = false;
                    }
                    else
                    {
                        Invoke("restartLevel", 0f);
                    }
                }
                else
                {
                    if (victim.GetComponent <Keybearer>() != null)
                    {
                        if (victim.GetComponent <Keybearer>().enabled == true)
                        {
                            GetComponent <Keybearer>().enabled     = true;
                            GetComponent <Keybearer>().posessedKey = victim.GetComponent <Keybearer>().posessedKey;
                        }
                    }
                    StartCoroutine(WaitToDestroy(victim));
                    victim     = lunchTargets[0];
                    moveTarget = victim.transform.position;
                }
            }
        }
        else
        {
            mStunCheck.UpdateStunnedTimer();
            if (victim != null)
            {
                moveTarget = victim.transform.position;
            }
            agent.Stop();
            if (GetComponent <Stunable>().mTypeofStun == Stunable.StunType.ShockStun)
            {
                GetComponent <Animator>().SetBool("ShockBool", true);
            }
            mAttacked = false;
        }
    }
    // Update is called once per frame
    void Update()
    {
        if (agent.velocity == Vector3.zero)
        {
            mBoostSpeed = false;
        }

        if (mCoughplaying)
        {
            if (Time.time > mCoughSoundEffectStartTimer + mCoughSoundEffect.length)
            {
                mCoughplaying = false;
            }
        }

        if (mShockplaying)
        {
            if (Time.time > mShockSoundEffectStartTimer + mShockSoundEffect.length)
            {
                mShockplaying = false;
            }
        }

        if ((NumberofShields > 0) && (mSidHover))
        {
            if (Time.time > mSidHoverStartTimer + mSIDHoverEffect.length)
            {
                mSidHover = false;
            }
        }

        if (mSidDied)
        {
            if (Time.time > mSidDieStartTimer + mSIDDieEffect.length)
            {
                mSidDied = false;
            }
        }

        if ((NumberofShields > 0) && (!mSidHover))
        {
            mAudioManager.PlaySoundEffect("Sid Hover");
            mSidHover           = true;
            mSidHoverStartTimer = Time.time;
        }

        //Decreasing breath while in gas
        if (mInGas)
        {
            if (mHasGasMask)
            {
                mGasBarLength = (mGasMaskTimer - (Time.time - mGasStartTime)) * 10;
                if (Time.time > mGasStartTime + mGasMaskTimer)
                {
                    mHasGasMask = false;
                    foreach (Gas gas in mGasesVisited)
                    {
                        gas.mGasMaskAffected = false;
                    }
                    mGasStartTime = Time.time;
                }
            }
            else
            {
                if (!mCoughplaying)
                {
                    mAudioManager.PlaySoundEffect("Cough");
                    mCoughplaying = true;
                    mCoughSoundEffectStartTimer = Time.time;
                }

                mGasBarLength = (mGasTimer - (Time.time - mGasStartTime)) * 10;
                if (Time.time > mGasStartTime + mGasTimer)
                {
                    mAudioManager.audio.Stop();
                    mAudioManager.PlaySoundEffect("Zombie Growl");
                    mInGas = false;
                    playDeathAnim();
                    agent.enabled = false;
                    GetComponentInChildren <SkinnedMeshRenderer>().enabled = false;
                    foreach (MeshRenderer mesh in GetComponentsInChildren <MeshRenderer>())
                    {
                        mesh.enabled = false;
                    }
                    GameObject zombie = (GameObject)Instantiate(Resources.Load("Zombie"));
                    zombie.transform.position = this.gameObject.transform.position;
                    zombie.transform.rotation = this.gameObject.transform.rotation;
                    Invoke("KilledbyGas", 2);
                    //Application.LoadLevel(Application.loadedLevel);
                    // Assets.CustomeScripts.Metrics.AddMetric("Killer ID was:", "The Gas");
                }
            }
        }


        //Decreasing shock tolerance while on a shock panel
        if (mInShock)
        {
            if (!mShockplaying)
            {
                mAudioManager.PlaySoundEffect("Shock");
                mShockplaying = true;
                mShockSoundEffectStartTimer = Time.time;
                anim.SetBool("ShockBool", true);
            }

            mShockBarLength = (mShockTimer - (Time.time - mShockStartTime)) * 10;
            if (Time.time > mShockStartTime + mShockTimer)
            {
                mAudioManager.audio.Stop();
                //mAudioManager.PlaySoundEffect("Zombie Growl");
                mInShock = false;
                playDeathAnim();
                agent.enabled = false;

                Invoke("KilledbyShock", 2);
                //Application.LoadLevel(Application.loadedLevel);
                //Assets.CustomeScripts.Metrics.AddMetric("Killer ID was:", "The Shock");
            }
        }

        if (!mStunCheck.IsStunned)
        {
            if (agent.enabled == true)
            {
                agent.Resume();
                anim.SetBool("ShockBool", false);
            }

            mStunCheck.UpdateStunInvinciblity();

            if (mBoostSpeed == true)
            {
                decreaseSpeedBoostTimer();
            }
            else
            {
                agent.speed        = speed;
                agent.acceleration = acceleration;
            }

            //Click-To-Move controls
            if (Input.GetMouseButton(0) && agent.enabled == true && !useJoystick)
            {
                RaycastHit hit;
                Ray        ray = Camera.main.ScreenPointToRay(Input.mousePosition);
                if (Physics.Raycast(ray, out hit))
                {
                    if (hit.collider.tag != "Companion" && !mouseOverGUI)
                    {
                        if (clickToPathfind)
                        {
                            clickToMoveTarget = hit.point;
                            clickToMoveIndicator.GetComponent <ClickToMovePointer>().RevealAtLocation(clickToMoveTarget);
                            clickToMoveTarget.y = 0;                            // clickToMoveTarget - new Vector3(0, clickToMoveTarget.y, 0);
                            agent.SetDestination(clickToMoveTarget);
                        }
                        else
                        {
                            Ray pathToPoint = new Ray(transform.position, hit.point - transform.position);
                            clickToMoveTarget.y = 0;                            // = clickToMoveTarget - new Vector3(0, clickToMoveTarget.y, 0);
                            clickToMoveTarget   = pathToPoint.GetPoint(1f);
                            clickToMoveIndicator.GetComponent <ClickToMovePointer>().RevealAtLocation(hit.point);
                            agent.SetDestination(clickToMoveTarget);
                        }
                    }
                }
                //else
                //anim.SetFloat("Speed", 0f);
            }            //End of Click-To-Move controls

            //Virtual Joystick Controls
            if (Input.GetMouseButton(0) && agent.enabled == true && useJoystick)
            {
                Vector3 joystickDestination = transform.position + (new Vector3(Joystick.mNormals.x, 0, Joystick.mNormals.y));
                agent.SetDestination(joystickDestination);
                Debug.Log("Using Joystick to Move");
            }

            float vertAccel = Input.acceleration.y + 0.5f;
            if ((Mathf.Abs(Input.acceleration.x) > 0.2f || Mathf.Abs(vertAccel) > 0.2f) && canTilt)
            {
                accelNeutral = false;
                clickToMoveIndicator.GetComponent <ClickToMovePointer>().Hide();
            }
            else
            {
                accelNeutral = true;
            }

            if (!accelNeutral && !((Input.GetAxis("Horizontal") != 0 || Input.GetAxis("Vertical") != 0) || Input.GetMouseButton(0)))
            {
                float horzMove = Input.acceleration.x / Mathf.Abs(Input.acceleration.x);
                float vertMove = vertAccel / Mathf.Abs(vertAccel);

                if (Mathf.Abs(Input.acceleration.x) <= 0.2f)
                {
                    horzMove = 0f;
                }

                if (Mathf.Abs(vertAccel) <= 0.2f)
                {
                    vertMove = 0f;
                }

                clickToMoveTarget = transform.position + new Vector3(horzMove * speed, 0, vertMove * speed);
                if (agent.enabled == true)
                {
                    agent.SetDestination(clickToMoveTarget);
                }
            }

            //WASD controls
            if (Input.GetAxis("Horizontal") != 0 || Input.GetAxis("Vertical") != 0)
            {
                clickToMoveIndicator.GetComponent <ClickToMovePointer>().Hide();
                clickToMoveTarget = transform.position + new Vector3(Input.GetAxis("Horizontal") * 1f, 0, Input.GetAxis("Vertical") * 1f);
                if (agent.enabled == true)
                {
                    agent.SetDestination(clickToMoveTarget);
                }
            }



            //Hide the arrow if the player is at the arrow
            if (Vector3.Distance(this.transform.position, clickToMoveIndicator.transform.position) < 1f)
            {
                //Debug.Log("At the arrow.");
                clickToMoveIndicator.GetComponent <ClickToMovePointer>().Hide();
            }

            if (!agent.hasPath)
            {
                clickToMoveIndicator.GetComponent <ClickToMovePointer>().Hide();
                anim.SetFloat("Speed", 0f);
            }
            else
            {
                anim.SetFloat("Speed", 2f);
            }
        }
        else
        {
            mStunCheck.UpdateStunnedTimer();
            if (agent.enabled == true)
            {
                agent.Stop();
            }
        }
    }