示例#1
0
        private void FixedUpdate()
        {
            // Reset
            attack        = false;
            abilityNumber = 0;

            // Read the inputs.

            // The line below is commented out because this game does not use a crouch (created by Unity team).
            //bool crouch = Input.GetKey(KeyCode.LeftControl);
            bool crouch = false;

            float h = CrossPlatformInputManager.GetAxis("Horizontal");

            // Don't do ability if one is currently in progress
            if (!m_Character.m_Anim.GetCurrentAnimatorStateInfo(0).IsName("UpperCut") ||
                !m_Character.m_Anim.GetCurrentAnimatorStateInfo(0).IsName("Dash") ||
                !m_Character.m_Anim.GetCurrentAnimatorStateInfo(0).IsName("GroundSmash") ||
                !m_Character.m_Anim.GetCurrentAnimatorStateInfo(0).IsName("Attack"))
            {
                // This is the UpperCut ability
                if (Input.GetButton("Fire2") && Input.GetKey(KeyCode.W) && m_Character.ability1CD <= 0)
                {
                    abilityNumber = 1;
                }
                // This is the Dash Ability (right)
                if (Input.GetButton("Fire2") && Input.GetKey(KeyCode.A) && m_Character.ability2CD <= 0)
                {
                    abilityNumber = 2;
                    right         = true;
                }
                // This is the Dash Ability (left)
                if (Input.GetButton("Fire2") && Input.GetKey(KeyCode.D) && m_Character.ability2CD <= 0)
                {
                    abilityNumber = 2;
                    right         = false;
                }

                // This is the Ground Smash Ability
                if (Input.GetButton("Fire2") && Input.GetKey(KeyCode.S) && m_Character.ability3CD <= 0)
                {
                    abilityNumber = 3;
                }
                if (Input.GetButton("Fire1") && m_Character.attackCD <= 0)
                {
                    attack = true;
                }
            }

            // Pass all parameters to the character control script.
            if (abilityNumber != 0)
            {
                // Do abilities
                m_Character.Abilities(abilityNumber, right);
            }
            else if (attack)
            {
                // Do attack
                m_Character.Attack();
            }
            else
            {
                // Move character (if groundsmash isn't active)
                if (!m_Character.groundSmashActive || !m_Character.m_Anim.GetCurrentAnimatorStateInfo(0).IsName("Dash"))
                {
                    m_Character.Move(h, crouch, m_Jump);
                }
            }

            m_Jump = false;
        }
示例#2
0
        private void FixedUpdate()
        {
            // Determine if the AI has reached the end of the path.
            if (path != null)
            {
                if (currentWayPoint >= path.vectorPath.Count)
                {
                    if (pathIsEnded)
                    {
                        return;
                    }

                    //Debug.Log("End of Path reached.");
                    pathIsEnded = true;
                    return;
                }

                pathIsEnded = false;

                // This logic is flawed
                //if (path.vectorPath[currentWayPoint].y - transform.position.y > 0.0f)
                //{
                //    if (jumpTimer <= 0)
                //    {
                //        jumpTimer = jumpTimerReset;
                //        Debug.Log("Jumping");
                //        m_Jump = true;
                //    }
                //}
                //else
                //{
                //    m_Jump = false;
                //}

                // Determine if the AI is close enough to the node to move to the next node in the path.
                float dist = Vector3.Distance(transform.position, path.vectorPath[currentWayPoint]);
                if (dist < nextWayPointDistance)
                {
                    currentWayPoint++;
                    return;
                }
            }

            Debug.Log("Jumping: " + m_Jump);

            // Don't allow AI to do actions if it is hurt or dead
            if (!m_Character.m_Anim.GetCurrentAnimatorStateInfo(0).IsName("Hurt") ||
                !m_Character.m_Anim.GetCurrentAnimatorStateInfo(0).IsName("death"))
            {
                // Do specialAbility
                if (specialAttack)
                {
                    specialAttack = false;
                    if (knight)
                    {
                        m_Character.Abilities(1, m_Character.m_FacingRight);
                    }
                    else if (ninja)
                    {
                        Move(h, true);
                        m_Character.Abilities(2, m_Character.m_FacingRight);
                    }
                    else if (juggernaut)
                    {
                        m_Character.Abilities(3, m_Character.m_FacingRight);
                    }

                    // This can only ever occur once per AI, but only 1 per level should be selected.
                    if (dropScroll)
                    {
                        dropScroll = false;
                        Instantiate(scroll, transform.position, transform.rotation);
                    }
                }

                // Do basic attack
                if (attack && m_Character.attackCD <= 0)
                {
                    m_Character.Attack();
                    if (!(knight || ninja || juggernaut))
                    {
                        GameObject clone;
                        clone = (Instantiate(projectilePrefab, projectilePoint.position, projectilePoint.rotation));

                        // Set speed based on direction AI is facing
                        if (!m_Character.m_FacingRight && (clone.GetComponent <Projectile>().speed > 0))
                        {
                            clone.GetComponent <Projectile>().speed *= -1;
                        }
                    }
                    attack = false;
                }

                // Move AI
                if (!m_Character.m_Anim.GetCurrentAnimatorStateInfo(0).IsName("Attack"))
                {
                    Move(h, m_Jump);
                }
            }
        }