Пример #1
0
    private void Update()
    {
        if (isDead)
        {
            if (Input.GetKeyDown(KeyCode.Escape))
            {
                SceneManager.LoadScene("MikkoHideOut");
            }


            return;
        }


        if (m_transform.position.y < -20)
        {
            GetComponent <Stats>().TakeDmg(10000);
        }

        if (m_stats != null && m_stats.isDead)
        {
            if (Input.GetKeyDown(KeyCode.R))
            {
                SceneManager.LoadScene("ForestScene");
            }
        }

        if (m_anim != null)
        {
            float speed = Mathf.Abs(m_move.magnitude);
            m_anim.SetFloat("Speed", speed);

            if (speed > 0 && !walkSound.isPlaying)
            {
                walkSound.Play();
            }
            else if (speed <= 0)
            {
                walkSound.Pause();
            }
        }

        if (!AllowMovement)
        {
            return;
        }

        /*if(Input.GetKeyDown(KeyCode.E))
         * {
         *  if(m_allowDash && canDash)
         *  {
         *      StartCoroutine(Dash());
         *      dashTimerForUI = 0;
         *      m_anim.SetTrigger("Charge");
         *  }
         * }*/

        if (comboStarted)
        {
            comboTimer += 1 * Time.deltaTime;
            if (comboTimer > 3)
            {
                GameManager gm = FindObjectOfType <GameManager>();
                comboTimer   = 0;
                currComboIdx = 0;
                comboStarted = false;
                if (gm.boboFace != null)
                {
                    gm.boboFace.sprite = gm.boboNormal;
                }
            }
        }

        if (Input.GetKeyDown(KeyCode.F))
        {
            AttemptEat();
        }

        if (Input.GetKeyDown(KeyCode.Space))
        {
            comboStarted = true;
            if (m_anim != null && mainHand.canMelee)
            {
                SaveFile    sf = FindObjectOfType <SaveFile>();
                GameManager gm = FindObjectOfType <GameManager>();
                if (gm.boboFace != null)
                {
                    gm.boboFace.sprite = gm.boboAngry;
                }

                /*if (currComboIdx >= sf.loadedSave.currentMaxCombo)
                 * {
                 *  currComboIdx = 0;
                 * }
                 * else
                 * {
                 *  currComboIdx++;
                 * }*/

                //Debug.Log(currComboIdx);

                switch (currComboIdx)
                {
                case 0:
                    m_anim.SetTrigger("Attack1");
                    m_anim.speed = mainHand.swingTimerMax;
                    mainHand.Swing();
                    currComboIdx++;
                    SoundManager.PlayASource("YetiSound1");
                    break;

                case 1:
                    m_anim.SetTrigger("Attack2");
                    m_anim.speed = mainHand.swingTimerMax;
                    offHand.Swing();
                    SoundManager.PlayASource("YetiSound2");
                    if (currComboIdx < sf.loadedSave.currentMaxCombo)
                    {
                        currComboIdx++;
                    }
                    else
                    {
                        currComboIdx = 0;
                        comboTimer   = 3;
                    }
                    break;

                case 2:
                    m_anim.SetTrigger("Attack3");
                    mainHand.Swing();
                    offHand.Swing();
                    currComboIdx = 0;
                    SoundManager.PlayASource("YetiSound3");
                    break;
                }

                //SoundManager.PlayASource("Swing");
            }
        }

        if (dashTimerForUI < dashCooldown)
        {
            dashTimerForUI += Time.deltaTime;
        }

        if (playerDash != null)
        {
            UpdateDashImage();
        }
    }
Пример #2
0
    public void FixedUpdate()
    {
        if (!isEnabled)
        {
            return;
        }

        //not sure if needed
        if (isMelee)
        {
            if (chase && Vector3.Distance(transform.position, lastSeenSpot) >= 3 && !stop)
            {
                Move((lastSeenSpot - transform.position).normalized);

                if (m_anim != null)
                {
                    m_anim.SetFloat("Speed", Mathf.Abs((lastSeenSpot - transform.position).normalized.magnitude));
                }

                if (pc != null)
                {
                    transform.LookAt(pc.transform.position);
                }
            }
            else if (chase && Vector3.Distance(transform.position, lastSeenSpot) <= 3)
            {
                //chase = false;
                if (m_anim != null)
                {
                    m_anim.SetFloat("Speed", 0);
                }
            }
            else
            {
                //do idle or move untill wall or something
                if (m_anim != null)
                {
                    m_anim.SetFloat("Speed", 0);
                }
            }


            if (Vector3.Distance(transform.position, pc.transform.position) <= 3)
            {
                if (curWeapon != null)
                {
                    if (curWeapon.GetType() == typeof(Melee))
                    {
                        Melee sword = (Melee)curWeapon;
                        if (sword.swingTimer <= 0)
                        {
                            stop = true;
                            sword.Swing();

                            if (m_anim != null)
                            {
                                m_anim.SetTrigger("Attack");
                                SoundManager.PlayASource("Dog3");
                            }
                        }
                        else
                        {
                            stop = false;
                        }
                    }
                }
            }
        }
        //fix ranged
        else if (isRanged)
        {
            //run to shoot distance
            if (chase && Vector3.Distance(transform.position, pc.transform.position) >= detectDistance + 5)
            {
                chase = false;
            }
            else if (chase && Vector3.Distance(transform.position, lastSeenSpot) >= shootDistance)
            {
                if (pc != null)
                {
                    transform.LookAt(pc.transform.position);
                }

                if (GetComponent <Gun>().canShoot)
                {
                    Move((lastSeenSpot - transform.position).normalized);
                }

                if (m_anim != null)
                {
                    m_anim.SetFloat("Speed", 1);
                }
            }
            //run away from player
            else if (chase && Vector3.Distance(transform.position, lastSeenSpot) <= escapeDistance)
            {
                if (pc != null)
                {
                    transform.LookAt(pc.transform.position);
                }

                if (GetComponent <Gun>().canShoot)
                {
                    Move((transform.position - lastSeenSpot).normalized);
                }

                if (m_anim != null)
                {
                    m_anim.SetFloat("Speed", 1);//Mathf.Abs((lastSeenSpot - transform.position).normalized.magnitude));
                }
                //maybe shoot while running?
                //Shoot();
            }
            else if (chase && Vector3.Distance(transform.position, pc.transform.position) >= escapeDistance)
            {
                if (pc != null)
                {
                    transform.LookAt(pc.transform.position);
                }

                if (m_anim != null)
                {
                    m_anim.SetFloat("Speed", 0);
                }

                Shoot();
                //chase = false;
            }
            else
            {
                //do idle or move untill wall or something
                if (m_anim != null)
                {
                    m_anim.SetFloat("Speed", 0);
                }
            }
        }
        //add scout who runs
        else if (isScout)
        {
            if (chase)
            {
                if (pc != null)
                {
                    transform.LookAt(pc.transform.position);
                }

                if (homeCamp != null && Vector3.Distance(transform.position, homeCamp.transform.position) <= 5)
                {
                    hasArrivedBase = true;
                    chase          = false;
                }

                // run to home base
                if (homeCamp != null && !hasArrivedBase)
                {
                    Move((homeCamp.transform.position - transform.position).normalized);
                }
                else if (Vector3.Distance(transform.position, lastSeenSpot) <= escapeDistance)
                {
                    Move((transform.position - lastSeenSpot).normalized);
                }

                if (m_anim != null)
                {
                    m_anim.SetFloat("Speed", 1);//Mathf.Abs((lastSeenSpot - transform.position).normalized.magnitude));
                }
                if (Vector3.Distance(transform.position, pc.transform.position) >= 17 && hasArrivedBase)
                {
                    chase = false;
                }
            }
            else
            {
                if (m_anim != null)
                {
                    m_anim.SetFloat("Speed", 0);
                }
            }
        }

        if (transform.position.y < -20)
        {
            Destroy(gameObject);
        }
    }