Beispiel #1
0
    IEnumerator SleepForIdle(float timeToWait, Skel_Control skeleControl, Animator animate)
    {
        yield return(new WaitForSecondsRealtime(timeToWait));

        _idleDone = true;
        skeleControl.setWalk(animate);
    }
Beispiel #2
0
    void SetInitialReferences()
    {
        checkRate      = Random.Range(0.8f, 1.2f);
        myTransform    = transform;
        detectionLayer = 1 << 8;

        animate          = GetComponent <Animator>();
        follow           = GetComponent <Follow>();
        pathFollowScript = GetComponent <PathingFollow>();
        string tempName = this.name.Substring(this.name.Length - 1);

        pathScript   = GameObject.Find("2D_Player(Clone)").GetComponent <clickDragSpawn>();
        agent        = GetComponent <NavMeshAgent>();
        skeleControl = GetComponent <Skel_Control>();
        playerScript = null;
        combatScript = GetComponent <Combat>();
    }
Beispiel #3
0
    // Function to chase player if in range
    public void FollowThem(Animator animate, NavMeshAgent agent, Vector3 playerLocation, Skel_Control skeleControl, Combat combatScript, Player playerScript)
    {
        Vector3 direction       = playerLocation - this.transform.position;
        bool    isCurrentAttack = animate.GetCurrentAnimatorStateInfo(0).IsName("Attack");

        if (Vector3.Distance(playerLocation, this.transform.position) < 25)
        {
            direction.y = 0;
            if (!isCurrentAttack)
            {
                this.transform.rotation = (Quaternion.Slerp(this.transform.rotation, Quaternion.LookRotation(direction), 0.1f));
            }

            if (direction.magnitude > 5)
            {
                if (!isCurrentAttack)
                {
                    agent.Resume();
                    agent.SetDestination(playerLocation);
                    agent.speed        = 7;
                    agent.acceleration = 8;
                }
                skeleControl.setRun(animate);                   // outside of loop to tell attack to stop
            }

            else
            {
                skeleControl.setAttack(animate);
                if (hitting)
                {
                    hitting = false;
                    StartCoroutine(SleepForAttack());
                    combatScript.Hit(playerLocation, playerScript);
                }
                agent.SetDestination(this.transform.position);
                agent.velocity = Vector3.zero;
                agent.Stop();

                // then make it so he can turn at the end
                if (attackSleep)
                {
                    attackSleep             = false;
                    this.transform.rotation = (Quaternion.Slerp(this.transform.rotation, Quaternion.LookRotation(direction), 0.1f));
                    attackSleep             = true;
                }
            }
        }
    }
Beispiel #4
0
    public void Patrol(List <Transform> actualPath, NavMeshAgent agent, Animator animate, Skel_Control skeleControl)
    {
        agent.speed        = 3;
        agent.acceleration = 3;
        Vector3 direction = actualPath[currentNode].position - this.transform.position;

        if (Vector3.Distance(actualPath[currentNode].position, this.transform.position) < roomToMove)
        {
            //if done with idle animation
            if (_idleDone)
            {
                currentNode++;
                waitForIdle = true;
                _idleDone   = false;
                if (currentNode >= actualPath.Count)
                {
                    currentNode = 0;
                    actualPath.Reverse();
                }
            }
            else
            {
                if (waitForIdle)
                {
                    waitForIdle = false;
                    skeleControl.setIdle(animate);
                    StartCoroutine(SleepForIdle((animate.GetCurrentAnimatorStateInfo(0).length), skeleControl, animate));
                }
            }
        }
        else
        {
            skeleControl.setWalk(animate);
            this.transform.rotation = (Quaternion.Slerp(this.transform.rotation, Quaternion.LookRotation(direction), 0.1f));
            agent.SetDestination(actualPath[currentNode].position);
        }
    }