Esempio n. 1
0
    // Update is called once per frame
    void Update()
    {
        Vector3 target          = targetedPlayer.GetPosition();
        Vector3 targetDirection = directionFromCat(target);

        // the second argument, upwards, defaults to Vector3.up
        Quaternion rotation = Quaternion.LookRotation(targetDirection, Vector3.up);

        transform.rotation = rotation;

        reachedTarget = CollisionRay(targetDirection);
        inView        = _renderer.IsVisibleFrom(targetedPlayer.cameraHelper.camera);
        bool walking = !reachedTarget && !inView;

        if (walking && !_animator.GetCurrentAnimatorStateInfo(0).IsName("Cat_Sit"))
        {
            _body.MovePosition(transform.position + targetDirection * speed * Time.deltaTime);
        }
        _animator.SetBool("isWalking", walking);
    }