所以这是我到目前为止制作的代码,它用于围绕太空中的一个轨道运行的摄像机。
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Lean.Touch;
public class CameraOrbit : TopClass
{
[Tooltip("Ignore fingers with StartedOverGui?")]
public bool ignoreGuiFingers = true;
[Tooltip("Ignore fingers if the finger count doesn't match? (0 = any)")]
public int requiredFingerCount = 1;
[Tooltip("The sensitivity of the movement, use -1 to invert")]
public float sensitivity = 0.25f;
public Vector3 target = Vector3.zero;
protected void LateUpdate()
{
// Get the fingers we want to use
List<LeanFinger> fingers = LeanTouch.GetFingers(ignoreGuiFingers, requiredFingerCount);
// Get the scaled delta of all the fingers
Vector2 delta = LeanGesture.GetScaledDelta(fingers);
transform.RotateAround(target, Vector3.up, delta.x * sensitivity);
transform.RotateAround(target, Vector3.right, delta.y * sensitivity);
transform.LookAt(target);
}
}
到目前为止,这种方法很有效,但有两件事令人讨厌,而我却不知道如何修复
经过大量Google搜索,我尝试过这些链接
但它们都没有正常工作,或者我无法让它们适应我的需要
任何帮助都会很棒,提前谢谢
答案 0 :(得分:1)
我认为到目前为止我找到了答案。我也有人测试它,他们喜欢它,所以我可能找到了解决方案。
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Lean.Touch;
public class CameraOrbit : TopClass
{
[Tooltip("Ignore fingers with StartedOverGui?")]
public bool ignoreGuiFingers = true;
[Tooltip("Ignore fingers if the finger count doesn't match? (0 = any)")]
public int requiredFingerCount = 0;
[Tooltip("The sensitivity of the movement, use -1 to invert")]
public float sensitivity = 0.25f;
public float min = 45f;
public float max = 315f;
public Vector3 target = Vector3.zero; //this is the center of the scene, you can use any point here
protected void LateUpdate()
{
// Get the fingers we want to use
List<LeanFinger> fingers = LeanTouch.GetFingers(ignoreGuiFingers, requiredFingerCount);
// Get the world delta of all the fingers
Vector2 delta = LeanGesture.GetScaledDelta(fingers);
transform.RotateAround(target, Vector3.up, delta.x * sensitivity);
transform.RotateAround(target, Vector3.right, delta.y * sensitivity);
Vector3 angles = transform.eulerAngles;
angles.x = Mathf.Clamp(angles.x, min, max);
angles.y = Mathf.Clamp(angles.y, min, max);
angles.z = 0;
transform.eulerAngles = angles;
transform.LookAt(target);
}
}
如果我希望相机始终具有向上的点,在我的情况下,它保持z轴为0. x和y轴只需要保持检查。
如果它对任何人有帮助,我从上面修改的唯一内容就是
...
public float min = 45f;
public float max = 315f;
...
Vector3 angles = transform.eulerAngles;
angles.x = Mathf.Clamp(angles.x, min, max);
angles.y = Mathf.Clamp(angles.y, min, max);
angles.z = 0;
transform.eulerAngles = angles;
感谢@yes指出我正确的方向