Beispiel #1
0
    private void Move()
    {
        float h = Input.GetAxisRaw("Horizontal");
        float v = Input.GetAxisRaw("Vertical");

        controllable.Move(new Vector3(h, 0.0f, v));
    }
Beispiel #2
0
        // Update is called once per frame
        void FixedUpdate()
        {
            if (state.isDead)
            {
                navMeshAgent.enabled = false;
                return;
            }

            if (enableMouseControl && Input.GetMouseButton(1))
            {
                Ray        ray = Camera.main.ScreenPointToRay(Input.mousePosition);
                RaycastHit hit;
                if (Physics.Raycast(ray, out hit, Mathf.Infinity, floorMask))
                {
                    SetDestination(hit.point);
                }
            }

            UpdatePath();

            if (destination.HasValue && (path.status != NavMeshPathStatus.PathInvalid) && (path.corners.Length > 0))
            {
                Vector3?nextPoint = GetNextPoint();
                if (nextPoint.HasValue)
                {
                    controller.Move(nextPoint.Value - transform.position);
                }
                else
                {
                    controller.Move(Vector3.zero);
                }
            }
            else
            {
                controller.Move(Vector3.zero);
            }

            if (destination.HasValue)
            {
                movementDestinationMarker.SetActive(true);
                movementDestinationMarker.transform.position = destination.Value;
            }
            else
            {
                movementDestinationMarker.SetActive(false);
            }
        }