Пример #1
0
        private void OnUpdate()
        {
            character.Aiming = Input.GetButton("Fire2");
            var moveVector = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));

            moveVector     = Quaternion.Euler(0, camera.transform.rotation.eulerAngles.y, 0) * moveVector;
            character.Move = moveVector;

            if (character.Aiming)
            {
                character.Fire = Input.GetButton("Fire1");
                if (InputTools.MouseToFloorPoint(camera, 40, floorMask, out var point))
                {
                    point += Vector3.up; //do not shoot the floor)
                    character.AimPoint = point;
                }

                var direction = character.AimPoint - character.Position;
                direction.y         = 0;
                character.Direction = direction;
            }
            else if (moveVector.magnitude > 0)
            {
                character.Fire      = false;
                character.Direction = moveVector;
            }
        }
Пример #2
0
        private void OnUpdate()
        {
            var aim = Input.GetButton("Fire2");

            if (aim)
            {
                character.Aiming = true;

                character.Move = Vector3.zero;

                var layerMask = LayerMask.GetMask("Floor");
                if (InputTools.MouseToFloorPoint(Camera.main, 20, layerMask, out character.AimPoint))
                {
                    aimDrawer.Enable = true;
                    var p1 = character.Position;
                    aimDrawer.Draw(p1, character.AimPoint);
                    var direction = character.AimPoint - p1;
                    direction.y         = 0;
                    character.Direction = direction;
                }
                else
                {
                    aimDrawer.Enable = false;
                }
            }
            else
            {
                if (character.Aiming)
                {
                    aimDrawer.Enable = false;
                    character.Aiming = false;
                    character.ThrowCurrentItem();
                }

                var moveVector = new Vector3(
                    Input.GetAxis("Horizontal"),
                    0,
                    Input.GetAxis("Vertical"));
                moveVector     = Quaternion.Euler(0, camera.transform.rotation.eulerAngles.y, 0) * moveVector;
                character.Move = moveVector;

                if (moveVector.magnitude > 0)
                {
                    character.Direction = moveVector;
                }
            }
        }