Exemple #1
0
        // Update is called once per frame
        void Update()
        {
            inputDirection = Quaternion.Euler(0, cam.rotation.eulerAngles.y, 0) * new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical")).normalized;
            inputVelocity  = Mathf.Max(Mathf.Abs(Input.GetAxis("Horizontal")), Mathf.Abs(Input.GetAxis("Vertical")));

            float angle = Vector3.SignedAngle(transform.forward, inputDirection, Vector3.up);

            animator.SetFloat("direction", angle / 180);
            animator.SetFloat("velocity", inputVelocity);

            isAttacking = animator.GetCurrentAnimatorStateInfo(0).IsTag("attack");
            float time = animator.GetCurrentAnimatorStateInfo(0).normalizedTime;

            if (hitController.IsDead)
            {
                if (Input.GetButtonDown("Fire1"))
                {
                    hitController.Revive();
                }
                return;
            }
            if (animator.GetCurrentAnimatorStateInfo(0).IsName("Default") || (isAttacking && time > 0.5f))
            {
                FindTarget();
                if (Input.GetButtonDown("Fire1") && !isRun)
                {
                    animator.SetBool("side", !animator.GetBool("side"));
                    animator.SetInteger("number", Random.Range(0, 3));
                    animator.SetTrigger("attack");
                    hitController.Attack();
                }


                /*if (Input.GetKeyDown(KeyCode.K)) {
                 *  animator.SetBool("side", !animator.GetBool("side"));
                 *  animator.SetInteger("number", 3);
                 *  animator.SetTrigger("attack");
                 * }*/
            }

            if (Input.GetButtonDown("Fire3"))
            {
                isRun = true;
                animator.SetBool("run", true);
                //Time.timeScale = 1;
            }
            if (Input.GetButtonUp("Fire3"))
            {
                animator.SetBool("run", false);
                isRun = false;
            }

            Vector3 pos = transform.TransformPoint(new Vector3(0, 0.6f, 1));

            if (target != null)
            {
                pos = target.position;
            }
            if (lookAtTimer > 0)
            {
                lookAtTimer -= Time.deltaTime;
                lookAtPos    = Vector3.Lerp(lookAtPos, pos, (2 - lookAtTimer) / 2);
            }
            else
            {
                lookAtPos = pos;
            }
        }
        // Update is called once per frame
        void Update()
        {
            if (hitController.IsDead)
            {
                return;
            }
            //inputDirection = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical")).normalized;
            //inputVelocity = Mathf.Max(Mathf.Abs(Input.GetAxis("Horizontal")), Mathf.Abs(Input.GetAxis("Vertical")));

            if (targetHead != null)
            {
                inputDirection = moveTargetPosition - rb.position;
            }
            else
            {
                inputDirection = Vector3.zero;
            }

            float vel = Mathf.Clamp(inputDirection.magnitude * 2, -1, 1);

            inputVelocity = Mathf.Abs(vel);

            float angle = Vector3.SignedAngle(transform.forward, (inputDirection * vel).normalized, Vector3.up);

            animator.SetFloat("direction", angle / 180);
            animator.SetFloat("velocity", inputVelocity);

            isAttacking = animator.GetCurrentAnimatorStateInfo(0).IsTag("attack");
            float time = animator.GetCurrentAnimatorStateInfo(0).normalizedTime;

            float dist = Vector3.Distance(targetBody.position, rb.position);

            if (dist <= 0.6f && !isRun)
            {
                if (animator.GetCurrentAnimatorStateInfo(0).IsName("Default"))
                {
                    animator.SetBool("side", !animator.GetBool("side"));
                    animator.SetInteger("number", Random.Range(0, 3));
                    animator.SetTrigger("attack");
                    hitController.Attack();
                }

                /*if (Input.GetKeyDown(KeyCode.K)) {
                 *  animator.SetBool("side", !animator.GetBool("side"));
                 *  animator.SetInteger("number", 3);
                 *  animator.SetTrigger("attack");
                 * }*/
            }

            if (dist > 6 && !isRun)
            {
                isRun = true;
                animator.SetBool("run", true);
                //Time.timeScale = 1;
            }
            if (dist <= 6 && isRun)
            {
                animator.SetBool("run", false);
                isRun = false;
            }
        }