我正在统一创建一个纸牌游戏。在那,我需要对角翻转一张卡片。我曾尝试使用旋转和翻译方法,但不幸的是我无法归档目标。我已将 YouTube 链接与此主题相关联。任何人都可以帮助我克服这个问题?
问问题
552 次
1 回答
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);
}
你可以从这个问题中阅读更多关于它以及如何使用它的信息
于 2017-02-07T08:32:51.910 回答