unity list循环
复制的感觉挺有用就保存下来
using system.collections;
using system.collections.generic;
using unityengine;
public class current : monobehaviour {
private list<int> content = new list<int>
{
5,
6,
7,
13,
8,
9,
10,
11,
12,
14
};
//列表当前id
private int currentid = 0;
//下一个id
public int nextid
{
get
{
currentid++;
print("数:" + currentid);
currentid = currentid % content.count;
print("余数:" + currentid);
return currentid;
}
}
//上一个id
public int lastid
{
get
{
currentid--;
if (currentid < 0) currentid = content.count - 1;
print("数:" + currentid);
currentid = currentid % content.count;
print("余数:" + currentid);
return currentid;
}
}
private void update()
{
if (input.getmousebuttondown(0))
{
print(content[nextid]);
}
if (input.getmousebuttondown(1))
{
print(content[lastid]);
}
}
}
上一篇: 关于导包问题
下一篇: 设计模式之模板方法模式(二)