我正在统一创造纸牌游戏。在那,我需要在对角线上翻转一张卡片。我尝试过使用旋转和翻译方法,但不幸的是我无法归档目标。我已将YouTube链接附加到此主题。任何人都可以帮我解决这个问题吗?
答案 0 :(得分:0)
我有这个代码用于卡片切换。您需要更改旋转的数字以对角旋转它,但它应该适合您
IEnumerator FlipCard()
{
yield return StartCoroutine(Constants.CardFlipTime.Tweeng((u) => gameObject.transform.localEulerAngles = new Vector3(0f, u, 0f),0, 90f));//begin the rotation
GetComponent<Image>().sprite = cardFrame;// change the card sprite since it currently not visible
Debug.Log("Rotated 90 deg");
yield return StartCoroutine(Constants.CardFlipTime.Tweeng((u) => gameObject.transform.localEulerAngles = new Vector3(0f, u, 0f), 90, 0f));//finish the rotation
}
这是我用来做平滑的值的Tweeng函数:
/// <summary>
/// Generic static method for asigning a action to any type
/// </summary>
/// <typeparam name="T"> generic</typeparam>
/// <param name="duration">Method is called on the float and same float is used as the duration</param>
/// <param name="vary">Action to perform over given duration</param>
/// <param name="start">Starting value for the action</param>
/// <param name="stop">End value of the action</param>
/// <returns>null</returns>
public static IEnumerator Tweeng<T>(this float duration, Action<T> vary,T start, T stop)
{
float sT = Time.time;
float eT = sT + duration;
Delegate d;
if (typeof(T) == typeof(float))
d = (Func<float, float, float, float>)Mathf.SmoothStep;
else if (typeof(T) == typeof(Vector3))
d = (Func<Vector3, Vector3, float, Vector3>)Vector3.Lerp;
else if (typeof(T) == typeof(Quaternion))
d = (Func<Quaternion, Quaternion, float, Quaternion>)Quaternion.RotateTowards;
else
throw new ArgumentException("Unexpected type " + typeof(T));
Func<T, T, float, T> step = (Func<T, T, float, T>)d;
while (Time.time < eT)
{
float t = (Time.time - sT) / duration;
vary(step(start, stop, t));
yield return null;
}
vary(stop);
}
您可以在this问题
中详细了解它以及如何使用它