Пример #1
0
 private void FixedUpdate()
 {
     if (!isFirstSetPos)
     {
         playerController.Move(dir);
     }
 }
Пример #2
0
    void Update()
    {
        Vector3 moveInput    = new Vector3(Input.GetAxisRaw("Horizontal"), 0, Input.GetAxisRaw("Vertical"));
        Vector3 moveVelocity = moveInput.normalized * moveSpeed;

        controller.Move(moveVelocity);


        Ray   ray         = viewCamera.ScreenPointToRay(Input.mousePosition);
        Plane groundPlane = new Plane(Vector3.up, Vector3.up * gunControll.GunHeight);
        float rayDistance;

        if (groundPlane.Raycast(ray, out rayDistance))
        {
            Vector3 point = ray.GetPoint(rayDistance);
//            Debug.DrawLine(ray.origin, point, Color.red);
            controller.LookAt(point);
            crosshairs.transform.position = point;
            crosshairs.DetectTargets(ray);
            if ((new Vector2(point.x, point.z) - new Vector2(transform.position.x, transform.position.z)).sqrMagnitude > 1)
            {
                gunControll.Aim(point);
            }
        }

        if (Input.GetMouseButton(0))
        {
            gunControll.OnTriggerHold();
        }

        if (Input.GetMouseButtonUp(0))
        {
            gunControll.OnTriggerRelease();
        }

        if (Input.GetKeyDown(KeyCode.R))
        {
            gunControll.Reload();
        }
    }