这个代码是如何工作的:
private Animator anim;
void Start()
{
anim = GetComponent<Animator>();
}
而这个代码没有:
private Animator anim;
void Start()
{
Animator anim = GetComponent<Animator>();
}
非常简单,
用这行代码
private Animator anim;
您正在生成一个名为"的变量;anim";
这适用于整个脚本。
然后您正试图使另一个变量也命名为";anim";内部";开始";。
这是一个古老的术语:(
THIS表示生成一个名为"的新变量;anim":
void Start()
{
Animator anim = GetComponent<Animator>();
}
但是THIS意味着使用名为"的现有变量;anim":
void Start()
{
anim = GetComponent<Animator>();
}
你不能说";生成一个名为"anim"的新变量;因为整个脚本中已经有一个名为"anim"的变量!