Beispiel #1
0
 // Update is called once per frame
 void Update()
 {
     if (Vector3.Distance(transform.position, destinationController.GetDestination()) < 8f)
     {
         destinationController.CreateDestination();
         navAgent.SetDestination(destinationController.GetDestination());
     }
 }
Beispiel #2
0
    protected virtual void Update()
    {
        if (!inAction)
        {
            return;
        }
        // 自分の位置と接触してきたオブジェクトの位置とを計算して、距離と方向を出して正規化(速度ベクトルを算出)
        distination = (targetPos.transform.position - transform.position).normalized;
        distination = new Vector3(distination.x, 0f, 0f).normalized;

        if (distination.x == 1)
        {
            transform.LookAt(targetPos);
            transform.rotation = Quaternion.Euler(new Vector3(0, 90, 0));
        }
        else
        {
            transform.LookAt(targetPos);
            transform.rotation = Quaternion.Euler(new Vector3(0, -90, 0));
        }
        animator.SetFloat("Speed", navAgent.velocity.magnitude);

        //移動先決定
        if (Vector3.Distance(transform.position, destinationController.GetDestination()) < 0.5f)
        {
            destinationController.CreateDestination();
            navAgent.SetDestination(destinationController.GetDestination());
        }

        //攻撃開始

        /*if (Vector3.Distance(transform.position, targetPos.position) < 0f)
         * {
         *  Debug.Log(navAgent.remainingDistance);
         *  timeleft -= Time.deltaTime;
         *  if (timeleft <= 0.0)
         *  {
         *      timeleft = 2.0f;
         *      attackIndex = Random.Range(1, 101);
         *      Debug.Log(attackIndex);
         *
         *      if (1 <= attackIndex && attackIndex <= 21)
         *      {
         *          animator.SetTrigger("H-Atk");
         *      }
         *      else if (31 <= attackIndex && attackIndex <= 51)
         *      {
         *          animator.SetTrigger("Comb-Atk");
         *      }
         *      else
         *      {
         *          animator.SetTrigger("L-Atk");
         *      }
         *  }
         * }*/
    }