[Unity]通过设置MeshRender的uv来显示图片的帧动画

这篇博客介绍了如何在Unity中通过设置MeshRenderer的uv坐标来实现3D物体上的帧动画。特别指出,这种方法只适用于Quad,使用其他3D物体可能会导致‘uv out of bounds’错误。作者提供了完整的代码参考链接,帮助读者理解并应用这种技术。
摘要由CSDN通过智能技术生成

3d物体的仅Quad可用。

如果用其他3D物体,会报错

Mesh.uv is out of bounds. The supplied array needs to be the same size as the Mesh.vertices array.

...
/// <summary>
    /// Sets the frame.
    /// </summary>
    /// <param name="frame">Frame.</param>
    public void SetFrame(int frame)
    {
        if (this._framesCount == 1)
        {
            return;
        }
        float xUnitSize = 1.0f / this._tilesX;
        float yUnitSize = 1.0f / this._tilesY;
 
        int xIndex = frame % this._tilesX;
        int yIndex = frame / this._tilesX;
        yIndex = this._tilesY - yIndex - 1;
        Vector2[] uv = new Vector2[] {
			//正常朝向右
			/*new Vector2(xIndex * xUnitSize, yIndex * yUnitSize),//左下
			new Vector2(xIndex * xUnitSize, yIndex * yUnitSize) + new Vector2(xUnitSize, 0),//右下
			new Vector2(xIndex * xUnitSize, yIndex * yUnitSize) + new
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值