【发布时间】:2016-08-19 08:52:09
【问题描述】:
假设我有这个功能:
int num;
void aa()
{
num=0;
//Wait 1 sec
num++;
//Print ("num= "+num ..
//Wait 1 sec
num++;
//Print ("num= "+num ..
}
如果我同时调用 aa() 两次,我会得到:
num=1 from first time called
num=2 from second time called
num=3 from first time called
num=4 from second time called
但我希望结果是
num=1 from first time called
num=1 from second time called
num=2 from first time called
num=2 from second time called
所以我想要一个函数的多个实例,但不中断或与另一个实例混合。
注意:我使用的是 Unity 和 C#。
【问题讨论】:
-
听起来你需要
num成为aa中的局部变量而不是字段......或者在不同的对象上调用aa。如果没有更多信息,我们不能说更多。 -
听起来你需要实例......
标签: c# function unity3d methods