Esempio n. 1
0
    void Update()
    {
        CharacterController controller = GetComponent <CharacterController>();
        StatusC             stat       = GetComponent <StatusC>();

        if (!master)
        {
            stat.Death();
            return;
        }
        if (meleefwd && !stat.freeze)
        {
            Vector3 lui = transform.TransformDirection(Vector3.forward);
            controller.Move(lui * 5 * Time.deltaTime);
            return;
        }
        if (freeze || stat.freeze || GlobalConditionC.freezeAll)
        {
            return;
        }
        if (useMecanim)
        {
            animator.SetBool("hurt", flinch);
        }
        if (flinch)
        {
            cancelAttack = true;
            Vector3 lui = transform.TransformDirection(Vector3.back);
            controller.SimpleMove(lui * 5);
            return;
        }
        if ((master.position - transform.position).magnitude > 30.0f)
        {
            Vector3 pos = master.position;
            pos.y += 1.7f;
            transform.position = pos;
        }

        FindClosest();

        if (followState == AIStatef.FollowMaster)
        {
            //---------------------------------
            if ((master.position - transform.position).magnitude <= 3.0f)
            {
                followState = AIStatef.Idle;
                //mainModel.animation.CrossFade(idleAnimation.name, 0.2ff);
                if (!useMecanim)
                {
                    //If using Legacy Animation
                    mainModel.GetComponent <Animation>().CrossFade(idleAnimation.name, 0.2f);
                }
                else
                {
                    animator.SetBool("run", false);
                }
            }
            else
            {
                Vector3 forward = transform.TransformDirection(Vector3.forward);
                controller.Move(forward * speed * Time.deltaTime);

                Vector3 mas = master.position;
                mas.y = transform.position.y;
                transform.LookAt(mas);
            }

            //---------------------------------
        }
        else if (followState == AIStatef.Moving)
        {
            masterDistance = (transform.position - GetMasterPosition()).magnitude;
            if (masterDistance > detectRange + 5.0f)             //////////////////GetMasterPosition
            {
                followState = AIStatef.FollowMaster;
                //mainModel.animation.CrossFade(movingAnimation.name, 0.2f);
                if (!useMecanim)
                {
                    //If using Legacy Animation
                    mainModel.GetComponent <Animation>().CrossFade(movingAnimation.name, 0.2f);
                }
                else
                {
                    animator.SetBool("run", true);
                }
            }
            else if ((followTarget.position - transform.position).magnitude <= approachDistance)
            {
                followState = AIStatef.Pausing;
                //mainModel.animation.CrossFade(idleAnimation.name, 0.2f);
                if (!useMecanim)
                {
                    //If using Legacy Animation
                    mainModel.GetComponent <Animation>().CrossFade(idleAnimation.name, 0.2f);
                }
                else
                {
                    animator.SetBool("run", false);
                }
                //----Attack----
                //Attack();
                StartCoroutine(Attack());
            }
            else if ((followTarget.position - transform.position).magnitude >= lostSight)
            {            //Lost Sight
                GetComponent <StatusC>().health = GetComponent <StatusC>().maxHealth;
                followState = AIStatef.Idle;
                //mainModel.animation.CrossFade(idleAnimation.name, 0.2ff);
                if (!useMecanim)
                {
                    //If using Legacy Animation
                    mainModel.GetComponent <Animation>().CrossFade(idleAnimation.name, 0.2f);
                }
                else
                {
                    animator.SetBool("run", false);
                }
            }
            else
            {
                Vector3 forward = transform.TransformDirection(Vector3.forward);
                controller.Move(forward * speed * Time.deltaTime);

                Vector3 destiny = followTarget.position;
                destiny.y = transform.position.y;
                transform.LookAt(destiny);
            }
        }
        else if (followState == AIStatef.Pausing)
        {
            Vector3 destinya = followTarget.position;
            destinya.y = transform.position.y;
            transform.LookAt(destinya);

            distance       = (transform.position - GetDestination()).magnitude;
            masterDistance = (transform.position - GetMasterPosition()).magnitude;
            if (masterDistance > 12.0f)             //////////////////GetMasterPosition
            {
                followState = AIStatef.FollowMaster;
                //mainModel.animation.CrossFade(movingAnimation.name, 0.2f);
                if (!useMecanim)
                {
                    //If using Legacy Animation
                    mainModel.GetComponent <Animation>().CrossFade(movingAnimation.name, 0.2f);
                }
                else
                {
                    animator.SetBool("run", true);
                }
            }
            else if (distance > approachDistance)
            {
                followState = AIStatef.Moving;
                //mainModel.animation.CrossFade(movingAnimation.name, 0.2f);
                if (!useMecanim)
                {
                    //If using Legacy Animation
                    mainModel.GetComponent <Animation>().CrossFade(movingAnimation.name, 0.2f);
                }
                else
                {
                    animator.SetBool("run", true);
                }
            }
        }
        //----------------Idle Mode--------------
        else if (followState == AIStatef.Idle)
        {
            Vector3 destinyheight = Vector3.zero;
            if (followTarget)
            {
                destinyheight   = followTarget.position;
                destinyheight.y = transform.position.y - destinyheight.y;
                distance        = (transform.position - GetDestination()).magnitude;
            }

            masterDistance = (transform.position - GetMasterPosition()).magnitude;
            if (distance < detectRange && Mathf.Abs(destinyheight.y) <= 4 && followTarget)
            {
                followState = AIStatef.Moving;
                //mainModel.animation.CrossFade(movingAnimation.name, 0.2f);
                if (!useMecanim)
                {
                    //If using Legacy Animation
                    mainModel.GetComponent <Animation>().CrossFade(movingAnimation.name, 0.2f);
                }
                else
                {
                    animator.SetBool("run", true);
                }
            }
            else if (masterDistance > 3.0f)              //////////////////GetMasterPosition
            {
                followState = AIStatef.FollowMaster;
                //mainModel.animation.CrossFade(movingAnimation.name, 0.2f);
                if (!useMecanim)
                {
                    //If using Legacy Animation
                    mainModel.GetComponent <Animation>().CrossFade(movingAnimation.name, 0.2f);
                }
                else
                {
                    animator.SetBool("run", true);
                }
            }
        }
        //-----------------------------------
    }
Esempio n. 2
0
    // Token: 0x06000318 RID: 792 RVA: 0x0000C020 File Offset: 0x0000A420
    private void Update()
    {
        CharacterController component  = base.GetComponent <CharacterController>();
        StatusC             component2 = base.GetComponent <StatusC>();

        if (!this.master)
        {
            component2.Death();
            return;
        }
        if (this.meleefwd && !component2.freeze)
        {
            Vector3 a = base.transform.TransformDirection(Vector3.forward);
            component.Move(a * 5f * Time.deltaTime);
            return;
        }
        if (this.freeze || component2.freeze)
        {
            return;
        }
        if (this.useMecanim)
        {
            this.animator.SetBool("hurt", this.flinch);
        }
        if (this.flinch)
        {
            this.cancelAttack = true;
            Vector3 a2 = base.transform.TransformDirection(Vector3.back);
            component.SimpleMove(a2 * 5f);
            return;
        }
        if (this.allowFollowing && (this.master.position - base.transform.position).magnitude > 40f)
        {
            Vector3 position = this.master.position;
            position.y += 0.4f;
            position.x += UnityEngine.Random.Range(3f, 9f);
            position.z += UnityEngine.Random.Range(3f, 9f);
            base.transform.position = position;
        }
        if (this.searchEnemy)
        {
            this.FindClosest();
        }
        if (!this.followTarget)
        {
            this.FindClosest();
        }
        if (this.allowFollowing)
        {
            if (this.followState == AIfriendC.AIStatef.FollowMaster && this.allowFollowing)
            {
                if ((this.master.position - base.transform.position).magnitude <= this.minMasterDistance)
                {
                    this.followState = AIfriendC.AIStatef.Idle;
                    if (!this.useMecanim)
                    {
                        this.mainModel.GetComponent <Animation>().CrossFade(this.idleAnimation.name, 0.2f);
                    }
                    else
                    {
                        this.animator.SetBool("run", false);
                    }
                }
                else
                {
                    Vector3 a3 = base.transform.TransformDirection(Vector3.forward);
                    component.Move(a3 * this.speed * Time.deltaTime);
                    Vector3 position2 = this.master.position;
                    position2.y = base.transform.position.y;
                    base.transform.LookAt(position2);
                }
            }
            else if (this.followState == AIfriendC.AIStatef.Moving)
            {
                this.masterDistance = (base.transform.position - this.GetMasterPosition()).magnitude;
                if (this.masterDistance > this.detectRange + 5f)
                {
                    this.followState = AIfriendC.AIStatef.FollowMaster;
                    if (!this.useMecanim)
                    {
                        this.mainModel.GetComponent <Animation>().CrossFade(this.movingAnimation.name, 0.2f);
                    }
                    else
                    {
                        this.animator.SetBool("run", true);
                    }
                }
                else if ((this.followTarget.position - base.transform.position).magnitude <= this.approachDistance)
                {
                    this.followState = AIfriendC.AIStatef.Pausing;
                    if (!this.useMecanim)
                    {
                        this.mainModel.GetComponent <Animation>().CrossFade(this.idleAnimation.name, 0.2f);
                    }
                    else
                    {
                        this.animator.SetBool("run", false);
                    }
                    if (this.followTarget.tag != "Player")
                    {
                        base.StartCoroutine(this.Attack());
                        MonoBehaviour.print("Attacking");
                    }
                }
                else if ((this.followTarget.position - base.transform.position).magnitude >= this.lostSight)
                {
                    base.GetComponent <StatusC>().health = base.GetComponent <StatusC>().maxHealth;
                    this.followState = AIfriendC.AIStatef.Idle;
                    if (!this.useMecanim)
                    {
                        this.mainModel.GetComponent <Animation>().CrossFade(this.idleAnimation.name, 0.2f);
                    }
                    else
                    {
                        this.animator.SetBool("run", false);
                    }
                }
                else
                {
                    Vector3 a4 = base.transform.TransformDirection(Vector3.forward);
                    component.Move(a4 * this.speed * Time.deltaTime);
                    Vector3 position3 = this.followTarget.position;
                    position3.y = base.transform.position.y;
                    base.transform.LookAt(position3);
                }
            }
            else if (this.followState == AIfriendC.AIStatef.Pausing)
            {
                Vector3 position4 = this.followTarget.position;
                position4.y = base.transform.position.y;
                base.transform.LookAt(position4);
                this.distance       = (base.transform.position - this.GetDestination()).magnitude;
                this.masterDistance = (base.transform.position - this.GetMasterPosition()).magnitude;
                if (this.masterDistance > 12f)
                {
                    this.followState = AIfriendC.AIStatef.FollowMaster;
                    if (!this.useMecanim)
                    {
                        this.mainModel.GetComponent <Animation>().CrossFade(this.movingAnimation.name, 0.2f);
                    }
                    else
                    {
                        this.animator.SetBool("run", true);
                    }
                }
                else if (this.distance > this.approachDistance + 10f)
                {
                    this.followState = AIfriendC.AIStatef.Moving;
                    if (!this.useMecanim)
                    {
                        this.mainModel.GetComponent <Animation>().CrossFade(this.movingAnimation.name, 0.2f);
                    }
                    else
                    {
                        this.animator.SetBool("run", true);
                    }
                }
            }
            else if (this.followState == AIfriendC.AIStatef.Idle)
            {
                Vector3 position5 = this.followTarget.position;
                position5.y         = base.transform.position.y - position5.y;
                this.distance       = (base.transform.position - this.GetDestination()).magnitude;
                this.masterDistance = (base.transform.position - this.GetMasterPosition()).magnitude;
                if (this.distance < this.detectRange && Mathf.Abs(position5.y) <= 4f && this.followTarget)
                {
                    this.followState = AIfriendC.AIStatef.Moving;
                    if (!this.useMecanim)
                    {
                        this.mainModel.GetComponent <Animation>().CrossFade(this.movingAnimation.name, 0.2f);
                    }
                    else
                    {
                        this.animator.SetBool("run", true);
                    }
                }
                else if (this.masterDistance > this.maxMasterDistance)
                {
                    this.followState = AIfriendC.AIStatef.FollowMaster;
                    if (!this.useMecanim)
                    {
                        this.mainModel.GetComponent <Animation>().CrossFade(this.movingAnimation.name, 0.2f);
                    }
                    else
                    {
                        this.animator.SetBool("run", true);
                    }
                }
            }
        }
        else if (this.useMecanim)
        {
            this.animator.SetBool("run", false);
        }
        else
        {
            this.mainModel.GetComponent <Animation>().CrossFade(this.idleAnimation.name, 0.2f);
        }
    }