Я добавил этот скрипт на объект Panel в Canvas. Не могу понять как сделать управление по оси Y. Игра в 3D под Android.
using UnityEngine;
using UnityEngine.EventSystems;
public class CameraController : MonoBehaviour, IDragHandler, IBeginDragHandler, IEndDragHandler
{
public GameObject _cam;
public GameObject _player;
private Vector3 offset;
private float horizon;
private float vert;
public float rotateSpeed = 5.0f;
private bool _tuchX;
public bool tuch;
private Vector2 startPoint;
private Vector2 endPoint;
void Start()
{
offset = _player.transform.position - _cam.transform.position;
}
public void OnBeginDrag(PointerEventData eventData)
{
startPoint = new Vector2(eventData.delta.x, eventData.delta.y);
tuch = true;
}
public void OnDrag(PointerEventData eventData)
{
endPoint = new Vector2(eventData.delta.x, eventData.delta.y);
}
public void OnEndDrag(PointerEventData eventData)
{
tuch = false;
}
void Update()
{
if(startPoint.x < endPoint.x) _tuchX = false;
else _tuchX = true;
if(tuch)
{
if(_tuchX) horizon = -1;
else horizon = 1;
}
else horizon = 0;
horizon *= rotateSpeed;
}
void LateUpdate ()
{
_player.transform.Rotate(0, horizon, 0);
float desiredAngle = _player.transform.eulerAngles.y;
Quaternion rotation = Quaternion.Euler(0, desiredAngle, 0);
_cam.transform.position = _player.transform.position - (rotation * offset);
_cam.transform.LookAt(_player.transform);
}
}
Спасибо)