コード例 #1
0
        // Use this for initialization
        void Start()
        {
            anim = GetComponent<Animator>();
            navMeshAgent = GetComponent<NavMeshAgent>();
            AnimHelper = new AnimationUtilities();
            idleReadyDurationValue = 0f;
            idleStateHasChanged = false;
            timerStart = false;
            combatAnimationInitiated = false;
            animationPlayed = false;

            InitializeDefaultTierList();
            currentTierPlaying = new DefaultTier();
        }
コード例 #2
0
        // Update is called once per frame
        void Update()
        {
            RaycastHit hit;
            Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);

            if (Input.GetMouseButtonDown(0))
            {
                if (Physics.Raycast(ray, out hit, 500))
                {
                    navMeshAgent.SetDestination(hit.point);
                }
            }

            AnimatorStateInfo stateInfo = anim.GetCurrentAnimatorStateInfo(0);
            anim.SetFloat(speed, Mathf.Abs(navMeshAgent.velocity.magnitude));

            if (stateInfo.IsName("IdleReady") && !idleStateHasChanged)
            {
                //only set time once then compare with current running time to get len
                if (!timerStart)
                {

                    anim.SetFloat(idleReadyDuration, Time.time);

                    timerStart = true;
                    anim.SetBool(isIdleReady, true);
                }
                //check if speed is fast enough to count as a run
                if (Mathf.Abs(navMeshAgent.velocity.magnitude) > 0.5)
                {
                    idleStateHasChanged = true;
                    timerStart = false;
                    anim.SetBool(isIdleReady, false);
                    anim.SetBool(isRunning, true);
                }
                //check if 5 seconds have elapsed since being in ready
                else if (Time.time - anim.GetFloat(idleReadyDuration) > 5f)
                {
                    idleStateHasChanged = true;
                    timerStart = false;
                    anim.SetBool(isIdleReady, false);
                    anim.SetBool(isIdleReadyToIdleCalm, true);
                }
            }

            if (stateInfo.IsName("Run"))
            {
                idleStateHasChanged = false;
                if (Mathf.Abs(navMeshAgent.velocity.magnitude) < 0.5)
                {
                    anim.SetBool(isRunning, false);
                    anim.SetBool(isIdleReady, true);
                }
            }

            if (stateInfo.IsName("IdleCalm"))
            {
                idleStateHasChanged = false;
                if (Mathf.Abs(navMeshAgent.velocity.magnitude) > 0.5)
                {
                    anim.SetBool(isIdleReadyToIdleCalm, false);
                    anim.SetBool(isRunning, true);
                }
            }

            //iterates through all of the moves if there is no combat animation playing
            if (!combatAnimationInitiated)
            {
                //Debug.Log("TAKING INPUT FOR MOVES");
                foreach (var move in tierList)
                {
                    if (Input.GetKeyDown(move.combo[0].ToString()) && move.comboPressed.Count == 0)
                    {
                        move.comboPressed.Add(move.combo[0].ToString());
                    }
                    if (move.comboPressed.Count == 1)
                    {
                        if (move.comboPressed[0].Equals(move.combo[0].ToString()))
                        {
                            if (move.isInCoroutine) Debug.Log("Already in coroutine");
                            else
                            {
                                Debug.Log("starting coroutine");
                                StartCoroutine(move.CombatSequnce(Time.time));
                            }
                        }
                    }
                    if (move.comboActivated)
                    {
                        currentTierPlaying = move;
                        combatAnimationInitiated = true;

                        anim.SetBool(isCombat, true);
                        anim.SetBool(move.animationHash, true);

                        //clears all combo pressed
                        tierList.ForEach(x => x.comboPressed.Clear());

                        break;
                    }

                    if (move.comboPressed.Count > 0)
                    {
                        Debug.Log(string.Format("move {0} has: ", move.tier));
                        move.comboPressed.ForEach(x => Debug.Log(x.ToString()));
                        Debug.Log("***********************************************");
                    }

                }//foreach move

            }

            if (combatAnimationInitiated && stateInfo.IsName(currentTierPlaying.animationStateName))
            {
                animationPlayed = true;
            }

            if (combatAnimationInitiated && stateInfo.IsName("IdleReady") && animationPlayed)
            {
                //while playing animation
                for (int x=0; x<tierList.Count; x++)
                {
                    if (tierList[x].comboActivated)
                    {
                        //reset all variables
                        anim.SetBool(tierList[x].animationHash, false);
                        anim.SetBool(isCombat, false);

                        combatAnimationInitiated = false;
                        animationPlayed = false;

                        tierList[x].comboActivated = false;
                    }

                }//iterate tierList
                DefaultTier.isComboFinished = false;
            }//stop combat
        }