一个随便写的Unity3D的图片墙移动特效,喜欢的拿走吧

一个随便写的Unity3D的图片墙移动特效,喜欢的拿走吧

1,这是一个用于展示图片的动画效果,如下图所示:
在这里插入图片描述
很简单的代码:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PicCtrl : MonoBehaviour
{
    [System.Serializable]
    public class MyPicinfo
    {
        public string name;
        public string url;
        public int x;
        public int y;
        public Vector3 fromposi;
        public Vector3 toposi;
        public GameObject myobject;

        public void Setinfo(int xx, int yy, Vector3 from, Vector3 to, string mname, string murl)
        {
            name = mname;
            url = murl;
            x = xx;
            y = yy;
            fromposi = from;
            toposi = to;
        }
    }

    public MyPicinfo[,] myPicinfo;

    public GameObject picPrefab;

    public Transform CubeSet;

    public int xcount = 30, ycount = 60;

    public int speed;

    void SetPrefavInit()
    {
        myPicinfo = new MyPicinfo[xcount, ycount];
        for (int i = 0; i < xcount; i++)
        {
            for (int j = 0; j < ycount; j++)
            {
                myPicinfo[i, j] = new MyPicinfo();
                Vector3 tt = new Vector3(i * 53, j * 53, 0);
                Vector3 ff = tt + Vector3.up * 2000;
                myPicinfo[i, j].myobject = Instantiate(picPrefab, ff, Quaternion.identity, CubeSet);
                myPicinfo[i, j].Setinfo(i, j, ff, tt, "test", "null");
            }
        }
    }

    public bool isok = false;

    private float moveLength, movetemp, savetamp;
    //移动到目标位置
    void MoveToPosi()
    {
        movetemp = Time.fixedTime - savetamp;
        if (isok)
        {
            savetamp = Time.fixedTime;
            isok = false;
        }
        moveLength = Time.fixedDeltaTime * movetemp * speed;
        for (int i = 0; i < xcount; i++)
        {
            for (int j = 0; j < ycount; j++)
            {

                myPicinfo[i, j].myobject.transform.position =
                    Vector3.Lerp(myPicinfo[i, j].fromposi +
                    new Vector3(i * 300, j * 300, 0)
                    , myPicinfo[i, j].toposi
                    , moveLength * (ycount - j * 0.2f) * 0.1f + i * 0.01f);

                //myPicinfo[i, j].myobject.transform.localScale =
                //    Vector3.Lerp(Vector3.one *2
                //    , Vector3.one
                //    , moveLength + i * 0.01f);


            }
        }
    }

    // Start is called before the first frame update
    void Start()
    {
        SetPrefavInit();
    }

    // Update is called once per frame
    void Update()
    {
        MoveToPosi();
    }
}

附上资源:源码下载

评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值