コード例 #1
0
    // Update is called once per frame
    void Update()
    {
        if (agent.velocity.x < 0)
        {
            sprite.flipX = true;
        }
        else
        {
            sprite.flipX = false;
        }

        if (!agent.pathPending && !followingPlayer)
        {
            if (agent.remainingDistance - 0.5f <= agent.stoppingDistance)
            {
                if (!isHit)
                {
                    pathIndex = pathIndex + 1 > followedPath.Count - 1 ? 0 : pathIndex + 1;
                    agent.SetDestination(followedPath[pathIndex].transform.position);
                }
                else
                {
                    daddy.EnemyBack();
                    Destroy(this.gameObject);
                }
            }
        }

        if (attackTime < attackRate)
        {
            attackTime += Time.deltaTime;
        }

        if (Vector2.Distance(transform.position, player.position) < playerDetectionDistance && attackTime >= attackRate && !isHit)
        {
            attackTime = 0f;
            Attack();
        }
    }