Member 13947881 Ответов: 0

Нужна небольшая помощь с поворотом моей кодовой камеры


Итак я работаю над игрой сверху вниз для android но не могу заставить камеру вращаться при свайпе слева направо можете ли вы ребята помочь мне с этим потому что окружающая среда блокирует видео игроков поэтому я хочу чтобы они могли вращать камеру справа налево с помощью свайпа чтобы иметь возможность видеть в том направлении куда они движутся я пробовал так много разных способов сделать эту работу но все что я пробовал потерпело неудачу так что не можете ли вы помочь мне исправить это

using UnityEngine;

[ExecuteInEditMode]
public class FollowCamera : MonoBehaviour
{
    private Transform cacheTransform;
    public Transform CacheTransform
    {
        get
        {
            if (cacheTransform == null)
                cacheTransform = GetComponent<Transform>();
            return cacheTransform;
        }
    }

    // The target we are following
    public Transform target;
    public Vector3 targetOffset;
    [Header("Follow")]
    public float damping = 10.0f;
    public bool dontSmoothFollow;
    [Header("Look at")]
    public float lookAtDamping = 2.0f;
    public bool dontSmoothLookAt;
    [Header("Rotation")]
    public float xRotation;
    public float yRotation;
    [Tooltip("If this is TRUE, will update Y-rotation follow target")]
    public bool useTargetYRotation;
    [Header("Zoom")]
    public float zoomDistance = 10.0f;
    [Header("Zoom by ratio (Currently work well with landscape screen)")]
    public bool zoomByAspectRatio;
    public float zoomByAspectRatioWidth;
    public float zoomByAspectRatioHeight;
    public float zoomByAspectRatioMin;

    private void Update()
    {
        var targetPosition = target == null ? Vector3.zero : target.position;
        var targetYRotation = target == null ? 0 : target.eulerAngles.y;
        var wantedPosition = targetPosition + targetOffset;
        var wantedYRotation = useTargetYRotation ? targetYRotation : yRotation;

        // Convert the angle into a rotation
        var currentRotation = Quaternion.Euler(xRotation, wantedYRotation, 0);

        // Set the position of the camera on the x-z plane to:
        // distance meters behind the target
        wantedPosition -= currentRotation * Vector3.forward * zoomDistance;

        // Update position
        if (!dontSmoothFollow)
            CacheTransform.position = Vector3.Slerp(CacheTransform.position, wantedPosition, damping * Time.deltaTime);
        else
            CacheTransform.position = wantedPosition;

        // Always look at the target
        if (!dontSmoothLookAt)
        {
            Quaternion lookAtRotation = Quaternion.LookRotation(targetPosition + targetOffset - CacheTransform.position);
            CacheTransform.rotation = Quaternion.Slerp(CacheTransform.rotation, lookAtRotation, lookAtDamping * Time.deltaTime);
        }
        else
            CacheTransform.rotation = Quaternion.LookRotation(targetPosition + targetOffset - CacheTransform.position);

        if (zoomByAspectRatio)
        {
            var targetaspect = zoomByAspectRatioWidth / zoomByAspectRatioHeight;
            var windowaspect = (float)Screen.width / (float)Screen.height;
            var scaleheight = windowaspect / targetaspect;
            var diffScaleHeight = 1 - scaleheight;
            if (diffScaleHeight < zoomByAspectRatioMin)
                diffScaleHeight = zoomByAspectRatioMin;
            zoomDistance = diffScaleHeight * 20f;
        }
    }

    private void LateUpdate()
    {
#if UNITY_EDITOR
        // Update camera when it's updating edit mode (not play mode)
        if (!Application.isPlaying && Application.isEditor)
            Update();
#endif
    }
}


Что я уже пробовал:

я использовал разные методы вращения камеры но все они кажется не работают может быть я что то упускаю

Member 13947881

помогите мне пожалуйста

0 Ответов