Unity3d 如何在Unity中进行对角翻转动画
我正在unity中创建一个纸牌游戏。在这种情况下,我需要在对角线上翻转一张牌。我尝试过使用旋转和平移方法,但不幸的是,我无法归档目标。我已将此线程附加到YouTube链接。有人能帮我解决这个问题吗Unity3d 如何在Unity中进行对角翻转动画,unity3d,unityscript,unity2d,Unity3d,Unityscript,Unity2d,我正在unity中创建一个纸牌游戏。在这种情况下,我需要在对角线上翻转一张牌。我尝试过使用旋转和平移方法,但不幸的是,我无法归档目标。我已将此线程附加到YouTube链接。有人能帮我解决这个问题吗 我有这个卡片翻转代码。您将需要更改旋转的次数以使其沿对角线旋转,但它应该适合您 IEnumerator FlipCard() { yield return StartCoroutine(Constants.CardFlipTime.Tweeng((u) => gameO
我有这个卡片翻转代码。您将需要更改旋转的次数以使其沿对角线旋转,但它应该适合您
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
}
IEnumerator动画卡()
{
产生返回开始例程(Constants.CardFlipTime.Tweeng((u)=>gameObject.transform.localEulerAngles=new Vector3(0f,u,0f),0,90f));//开始旋转
GetComponent().sprite=cardFrame;//更改卡精灵,因为它当前不可见
调试日志(“旋转90度”);
产生返回开始例程(Constants.CardFlipTime.Tweeng((u)=>gameObject.transform.localEulerAngles=new Vector3(0f,u,0f),90,0f));//完成旋转
}
下面是我用来平滑lerp值的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);
}
//
///将操作指定给任何类型的通用静态方法
///
///一般的
///方法,并将相同的浮点用作持续时间
///在给定的持续时间内执行的操作
///操作的起始值
///行动的最终价值
///空的
公共静态IEnumerator Tweeng(此浮动持续时间、动作变化、T启动、T停止)
{
float sT=Time.Time;
浮动eT=sT+持续时间;
d代表;
如果(类型(T)=类型(浮动))
d=(Func)Mathf.SmoothStep;
else if(typeof(T)=typeof(Vector3))
d=(Func)Vector3.Lerp;
else if(typeof(T)=typeof(四元数))
d=(Func)四元数。旋转方向;
其他的
抛出新ArgumentException(“意外类型”+typeof(T));
Func步骤=(Func)d;
while(Time.Time
您可以从问题`FlipNew.Tweeng(这个float,System.Action,T,T)':扩展方法必须在非泛型静态类中定义此错误发生时。。类名是什么?公共静态类WhatEvernameYouWant{}