在unity中实现分页扩展(旋转3D)功能(UGUI)(4)

这次给大家介绍一个看起来是3D的效果的UI的切换
在实际应用中 别看起来不是那么呆板
在这里插入图片描述

我们要首先创建两个Image 通过修改point的位置 来改变旋转的轴
我们可以看到 有两个模块是两个不同的方向的旋转
在这里插入图片描述
在这里插入图片描述
我们分别把两块的pivot分别设为(0,0)和(1,1)默认为(0.5,0.5)

之后我们通过代码来修改旋转就可以了
这里我们仍然使用插值来实现 缓动

public class TurnUI : MonoBehaviour
{
    public enum TurnType
    {
        left,
        right
    };
    //使用枚举来分类左边和右边

    public bool isstart;
    public bool isend;
    private float timer=0;

    public TurnType type ;

    public static TurnUI instance;

    private void Awake()
    {
        instance = this;
    }
    private void Update()
    {
        if (isstart && type == TurnType.right)
        {
            timer += Time.deltaTime;

            transform.rotation = Quaternion.Euler(Vector3.Lerp(new Vector3(0, 0, 0), new Vector3(0, 180, 0), timer));
            if (timer > 1f)
            {
                isstart = false;
            }
        }
        if (isend && type == TurnType.right)
        {
            timer -= Time.deltaTime;

            transform.rotation = Quaternion.Euler(Vector3.Lerp(new Vector3(0, 0, 0), new Vector3(0, 180, 0), timer));
            if (timer < 0f)
            {
                isend = false;
            }
        }

        if (isstart && type == TurnType.left)
        {
            timer += Time.deltaTime;

            transform.rotation = Quaternion.Euler(Vector3.Lerp(new Vector3(0, 0, 0), new Vector3(0, -180, 0), timer));
            if (timer > 1f)
            {
                isstart = false;
            }
        }
        if (isend && type == TurnType.left)
        {
            timer -= Time.deltaTime;

            transform.rotation = Quaternion.Euler(Vector3.Lerp(new Vector3(0, 0, 0), new Vector3(0, -180, 0), timer));
            if (timer < 0f)
            {
                isend = false;
            }
        }
    }
}

希望这篇博文对你有帮助
如果有问题可以联系我 主页有我的联系方式

猜你喜欢

转载自blog.csdn.net/weixin_44302602/article/details/108119400