一个随便写的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();
}
}
附上资源:源码下载