Задать вопрос
@Porocia

Как сделать поворот камеры свайпами на Unity?

Хочу сделать поворот камеры свайпами на unity, но у меня никак не получается, камера начинает поворачиваться по оси z, а мне это не нужно.

using System.Collections;
using System.Collections.Generic;
using UnityEngine.EventSystems;
using UnityEngine;

public class move_android : MonoBehaviour, IPointerDownHandler, IDragHandler, IPointerUpHandler
{

    private Vector2 Origin;
    private Vector2 Direction;
    Vector3 ppos;

    int x;
    int y;


    public GameObject camera;
    public float sensX = 3f;
    public float sensY = 3f;
    private Quaternion OriginalRot;
    public Transform player;

    private void Awake()
    {
        Direction = Vector2.zero;
        OriginalRot = camera.transform.localRotation;
    }
    public void OnPointerDown(PointerEventData eventdata)
    {
        Origin = eventdata.position;
    }

    public void OnPointerUp(PointerEventData eventData)
    {
        OriginalRot = camera.transform.localRotation;
        Direction = Vector2.zero;

    }

    public void OnDrag(PointerEventData eventData)
    {
        Vector2 currentPozition = eventData.position;
        Vector2 directionRaw = currentPozition - Origin;
        Direction = directionRaw;

    }
    // 
    void Update()
    {

        Quaternion Xqua = Quaternion.AngleAxis(Direction.x, Vector3.up);
        Quaternion Yqua = Quaternion.AngleAxis(Direction.y, Vector3.left);

        camera.transform.rotation = OriginalRot * Xqua * Yqua;

    }
}
  • Вопрос задан
  • 92 просмотра
Подписаться 1 Простой 1 комментарий
Помогут разобраться в теме Все курсы
  • Нетология
    Разработчик игр на Unity
    13 месяцев
    Далее
  • Skillbox
    Middle-разработчик игр на Unity
    3 месяца
    Далее
  • GB (GeekBrains)
    Разработчик Игр на Unity
    10 месяцев
    Далее
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Похожие вопросы